Show related courses in single course page

Please add the given code in your wplms-customizer.php file at the end and before “?>” in wplms customizer plugin :

add_action('bp_after_course_body','wplms_modern_course_front_default');
function wplms_modern_course_front_default(){
?>
<div class="related_courses">
<h2><?php _e('Related Courses','wplms_modern');?></h2>
<?php
$terms = wp_get_post_terms(get_the_ID(),'course-cat');
$categories = array();
if(!empty($terms)){
foreach($terms as $term)
$categories[] = $term->term_id;
}
$args = apply_filters('wplms_moern_related_courses',array(
'post_type' => 'course',
'posts_per_page'=>3,
'post__not_in'=>array(get_the_ID()),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'course-cat',
'field' => 'id',
'terms' => $categories,
),
),
));
$args = apply_filters('wplms_carousel_course_filters',$args);
$courses = new WP_Query($args);

if($courses->have_posts()):
?>
<ul class="row">
<?php 
while($courses->have_posts()): $courses->the_post();
global $post;
echo '<li class="col-md-4">';

if(empty($style))
$style = 'course';

echo thumbnail_generator($post,$style,'medium');
echo '</li>';
endwhile;
?>
</ul>
<?php
else:
?>
<div class="message">
<p><?php _e('No related courses found','vibe');?></p>
</div>
<?php
endif;
wp_reset_postdata();
?>
</div>
<?php
}

 

 

Was this article helpful?

4 Comments

  1. foxycleop

    Thanks, this works good (I needed to fix the single (‘) and double quotes (“) to make it work.

    What is the criteria for “Related Course” selection – is it category based or random? or is there a way to manually set related courses for each course? Thanks!

  2. To add Related Courses after Course curriculum but before Course reviews, change the first line of the code to
    `add_action(‘wplms_after_course_description’,’wplms_modern_course_front_default’,99);`

Leave A Comment?