• I’m running WP 2.3.2. I have 2 questions on this code in my sidebar:

    <?php rewind_posts(); ?>
    
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
    	<?php if (in_category(11)) { ?>
    		<div class="sidenotes">
    		<?php echo $post->post_excerpt ?> <?php the_content(); ?>
    		</div>
    	<?php } ?>
    <?php endforeach; else: ?>
    	<?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>

    I have 1 post in category 11. Today (1/6/08 for me), if the date on that post is 11/29/07, that code displays no post content. If I change the date (and only the date) to 11/30/07, the content displays just fine. I’ve only noticed this behavior since I upgraded to 2.3.2, but I can’t swear to that.

    Why is that code affected by the post date?

    Secondly, with the right date, that code works as expected but only on the home page. I have a number of other pages (say a Videos page). If I surf to the Videos page, that code doesn’t output the post content, even though I have rewind_posts() at the top.

    In both the date case and surfing off the home page case, I never get the “Sorry, no posts…” message.

    Is there another problem with my loop that I’m missing?

    Thanks in advance for any pointers.

Viewing 1 replies (of 1 total)
  • Thread Starter frisco

    (@frisco)

    The solution to both of my problems is in this code:

    <?php $my_query = new WP_Query('category_name=Sidenotes&showposts=1'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<div class="sidenotes">
    	<?php the_content(); ?>
    	</div>
    <?php endwhile; ?>

    In looking over my first post, I replaced the deprecated start_wp() with the the_post() but that didn’t make a difference. I’m still at a loss to figure out why the date had an impact on the results. Anyone?

Viewing 1 replies (of 1 total)
  • The topic ‘Loop in sidebar’ is closed to new replies.