April 22, 201016 yr I've just installed the YARPP plugin on my blog to display related posts in my single.php - i.e. on the actual posts. I'm using one of the templates provided that utilises the wordpress 'post thumbnails' functionality which I use. The code within this template is: <?php /* Example template for use with post thumbnails Requires WordPress 2.9 and a theme which supports post thumbnails Author: mitcho (Michael Yo****aka Erlewine) */ ?> <h3>Related Posts</h3> <?php if ($related_query->have_posts()):?> <ol class="related-posts"> <?php while ($related_query->have_posts()) : $related_query->the_post(); ?> <?php if (function_exists('has_post_thumbnail')): if (has_post_thumbnail()):?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?><br /><?php the_title_attribute(); ?></a></li> <?php endif; endif; ?> <?php endwhile; ?> </ol> <?php else: ?> <p>No related posts.</p> <?php endif; ?> My problem is that if there are no related posts the text 'No related posts.' does not display. Anyone know why? Here's an example post with no related posts: http://www.milomade.co.uk/blog/2010/04/april-showers/ I've messed about with the PHP and whatever I do breaks the site - I'm crap at PHP, so would appreciate it if one of you experts out there could let me know if there is anything wrong with the above code and how to fix it. Thanks E
April 23, 201016 yr What is have_posts() returning? Try putting in something simple and see if it it the argument that is causing the problem. Try: <?php /* Example template for use with post thumbnails Requires WordPress 2.9 and a theme which supports post thumbnails Author: mitcho (Michael Yo****aka Erlewine) */ ?> <h3>Related Posts</h3> <?php if (!$related_query->have_posts()):?> <ol class="related-posts"> <?php while ($related_query->have_posts()) : $related_query->the_post(); ?> <?php if (function_exists('has_post_thumbnail')): if (has_post_thumbnail()):?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?><br /><?php the_title_attribute(); ?></a></li> <?php endif; endif; ?> <?php endwhile; ?> </ol> <?php else: ?> <p>No related posts.</p> <?php endif; ?> If that shows 'No related posts' then it is your 'have_posts()' method that is causing you trouble.
April 23, 201016 yr Author okay - by adding your version of the code I get the text 'No related posts' for every post I visit. Now what?
Create an account or sign in to comment