The Crazyness That Is The Wordpress Loop
Please be aware that this reference of crazyness is only in the most positive light. Read on for a useful Wordpress theming tip.
By Ron Scott March 9th, 2009
Shortly before the launch of iaR, I became aware of a Wordpress/PHP problem in the theme. This is the first site I’ve built that relies on two Wordpress loops on each page - the left column’s content, and the right column’s excerpts. The front page of this site displayed them almost the way I wanted them to. The single post pages? Not even close. But this afternooon I was able to fix both issues.
The single page was the most difficult. My original WP loop setup had the plain-jane PHP code, but this only made one post (and it’s excerpt) display in the sidebar. And that one post was also the one in the main content area. So after a few days of annoying PHP doodling, I came across this great little post on WPRecipes.com that helped me overcome the problem. The code:
query_posts('showposts=5&offset=1');
…is inserted into the
<?php
statement at the beginning of the loop. Want the whole code block? Kay.
<?php if (have_posts()) : ?> <!--the loop--> <?php query_posts('showposts=5&offset=0'); while (have_posts()) : the_post();//THE LOOP AND ALL THAT JAZZ
There you have it. Wordpress loops are crazy, but with a little help from Google and some knowledge of PHP, another challenged was roundhouse kicked.
Category: Design.
You can leave a response, or trackback from your own site.




