If the code from above works well in itself (without your if statements) – then it must be OK.
However, being a (mini)Loop, placing the if statements AFTER it I guess the if… checks the Loop that is just above/before it and not the main Loop of the page that is displayed. Just a hunch because I am not a coder.
I should mention here that I think the error might be in the IF and WHILE portions of the code or the ENDWHILE or ENDIF portions. The rest should be right. The code works perfectly as written.
Moshu, I think you’re on the right track. I’m hoping someone with more coding expertise can help.
Try this instead
<h2>Recently Posted</h2>
<ul>
<?php query_posts('showposts=10'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a><span class="recent_date"><?php the_time('n.j') ?></span></li>
<?php endwhile; ?>
</ul>
<?php rewind_posts(); ?>
You know that the query will show posts, so no reason to check if you will have posts. The last bit of code resets the loop if your going to be doing anything else with the loop.
Jeremy, I’ll try it right now and report back. Thanks for the quick response.
Nope. That didn’t do it.
Although the code you provided above does work, the problem I’m having didn’t go away.
Perhaps it’s my own code. Here’s what I have now:
…sidebar stuff
<!-- RECENTLY POSTED -->
<li class="widget">
<h2>Recently Posted</h2>
<ul>
<?php query_posts('showposts=10'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a><span class="recent_date"><?php the_time('n.j') ?></span></li>
<?php endwhile; ?>
</ul>
<?php rewind_posts(); ?>
</li>
<!-- ONLY ON HOME OR ARCHIVE PAGES -->
<?php if ( is_home() || is_archive() ) { ?>
…stuff I want to appear only on the Home or Archive pages…
<!-- END ONLY ON HOME OR ARCHIVE -->
<?php } ?>
…more sidebar stuff…
Is my conditional statement in error? I’m clueless when it comes to the : and ; thing.
I should note here that my theme has two sidebars that appear side by side. The above code also “turns off” the IF/THEN logic in the other sidebar, which appears to its right.
However, when I place my IF statement above the RECENTLY POSTED stuff, everything works fine.
you are trying to use php in the sidebar widget.. I don’t believe they offer this functionality standard. (I’m assuming your placing this code into one of the text widgets) If this is the case, download the phpwidget plugin, and place your code there..
if your not doing this in a widget.. try this change..
<?php while (have_posts()) : the_post() { ?>
<li><a href="<?php the_permalink() ?>"><?php the_title() ?></a><span class="recent_date"><?php the_time('n.j') ?></span></li>
<?php } ?>