Forum Moderators: coopster
<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo '';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" title="Read more on <?php the_title_attribute(); ?>"><img src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" alt="<?php the_title(); ?>" width="36" height="36" class="thumbnail" /></a>
<a href="<?php the_permalink() ?>" title="Read more on <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</li> <?php
endwhile;
}
}
?>
I don't know php myself. However when there are no related posts it doesn't display anything. How do I add a if statement so that when there are no related posts it displays: <p>There are currently no related posts</p>
Hope you can help
:-)
<a href="<?php the_permalink() ?>"
title="Read more on <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</li>
<?php
endwhile;
}
else{
echo("<p>There are currently no related posts</p>");
}
}
:-)
Just that some of my blog post didnt have any tags this prevents the else statement from appearing, I just added a random tag to the post and it then displayed:
<p>There are currently no related posts</p>
Thanks for your help, it was really helpful