Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

wp_link_pages breaking sidebar custom queries WordPress

  • SOLVED

I have a long page to post, so I'm splitting it into sections by using <!--nextpage-->, however, when I go to the second page or beyond of the page, my custom queries in the sidebar display the same content as the page, rather than the posts they are supposed to display.

Here's my page.php code:

<?php get_header(); ?>

<div id="inner_content">
<div class="pagecontent">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php wp_link_pages(); ?>
<?php endwhile; endif; ?>
</div>
</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>


Here's my sidebar.php code:

<div id="inner_sidebar">
<h2>Latest News </h2>
<?php $latestnews = new WP_Query('cat=1&showposts=2'); ?>
<?php if($latestnews->have_posts()) : ?><?php while($latestnews->have_posts()) : $latestnews->the_post(); ?>
<p><?php content('20'); ?></p>
<span class="more"><a href="<?php the_permalink(); ?>">read more</a></span>
<?php endwhile; endif; ?>
<div class="spacer"></div>
<h2>Blog </h2>
<?php $blog = new WP_Query('cat=3&showposts=1'); ?>
<?php if($blog->have_posts()) : ?><?php while($blog->have_posts()) : $blog->the_post(); ?>
<p><?php content('20'); ?></p>
<span class="more"><a href="<?php the_permalink(); ?>">read more</a></span>
<?php endwhile; endif; ?>
</div>


Here's a link to the page with the error (look at the difference in the sidebar between page 1 and the other pages): http://www.chapmanguitars.co.uk/about/interview-with-rob-chapman/

Thanks in advance

Answers (1)

2010-02-09

Tony Geer answers:

Try putting in:

<?php wp_reset_query(); ?>

Right at the start of your sidebar code. So it should look like this:

<div id="inner_sidebar">
<?php wp_reset_query(); ?>
<h2>Latest News </h2>

<?php $latestnews = new WP_Query('cat=1&showposts=2'); ?>

...and so on...

</div>


Dan Davies comments:

Unfortunately that didn't resolve the issue. I tried rewind_posts too.


Tony Geer comments:

Okay one more thing to try. It's basically trying the same thing in a slightly different way:

<?php
wp_reset_query();
query_posts('cat=1&showposts=2');

if (have_posts()) : ?>
<?php while (have_posts()) : the_post();

//pull out your posts' content here

endwhile; ?>
<?php endif; ?>


Try that see if it works. I also see you're using the_content('20'), is that a plugin? Try deactivating it if it is and see if that solves the problem.