if there are no related posts, show 'no related posts'
-
Below is my function,
function my_related_posts() { if (is_single()) { global $post; $current_post = $post->ID; $categories = get_the_category(); foreach ($categories as $category) : ?> <div class="recent-posts"> <?php $posts = get_posts('numberposts=5&category='. $category->term_id . '&exclude=' . $current_post); foreach($posts as $post) : ?> <div class="col-md-4"> <div class="featured-image-featured" class="img-responsive"> <?php if(has_post_thumbnail()) { the_post_thumbnail();} else { ?><img src="https://placehold.it/730x350" class="img-responsive"><?php }?> </div> <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> <div id="date-related"> <span id="day"><?php echo get_the_date('d'); ?></span> <span id="month"><?php echo get_the_date('M'); ?></span> <span id="year"><?php echo get_the_date('Y'); ?></span> </div> <article> <?php the_excerpt(); ?> </article> <div class="categories-title">Tags</div> <div class="categories"> <?php $categories = get_the_category(); $separator = ' '; $output = ''; if($categories){ foreach($categories as $category) { $output .= '<span>'.$category->cat_name.'</span>'.$separator; } echo trim($output, $separator); } ?> </div> </div> <?php endforeach; ?><?php endforeach; ?> </div> <?php } wp_reset_query(); } add_action('thesis_hook_after_post','my_related_posts');
I need to make it show ‘No related posts’ if there aren’t any.
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘if there are no related posts, show 'no related posts'’ is closed to new replies.