[Plugin: Yet Another Related Posts Plugin] Call to a member function have_posts() on a non-object er (2 posts)

  1. Darran
    Posted 5 years ago #

    I am trying to include YARP in my single.php page. This is my code:

    <div class="similar_posts">
    	<h3>Related Posts</h3>					
    	<?php if ($related_query->have_posts()):?>
    		<?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
    			<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    		<?php endwhile; ?>
    	<?php else: ?>
    		<p>No related posts.</p>
    	<?php endif; ?>					

    I am getting a "Call to a member function have_posts() on a non-object error on line 31" which refers to <?php if ($related_query->have_posts()):?>

    Where is this $related_query object declared or created? Would appreciate any help.

  2. You can't put the code from a YARPP template directly into your theme. You have to call related_posts() from your theme and then select your template file in the YARPP options.

    For more info: http://mitcho.com/blog/projects/yarpp-3-templates/

Topic Closed

This topic has been closed to new replies.

About this Topic