Method 1: This uses just 1 loop and allows you to style your first, second and then all other posts separately.
<?php if (have_posts()) : ?>
<?php // Initialize the counter
$counter = 0;
?>
<?php while (have_posts()) : the_post(); ?>
<?php if ($counter == 0) { ?>
// Display post #1 this way
<?php } elseif $counter == 1 { ?>
// Display second post this way
<?php } else { ?>
// All other posts are displayed like this
<?php } ?>
<?php // Add 1 to the counter
$counter++;
?>
<?php endwhile; ?>
// What you want displayed after the loop has run
<?php else : ?>
// What you want displayed if no posts are found
<?php endif; ?>
Method 2: Use multiple loops in your page. This is sometimes easier if your posts don’t directly follow each other in the source code.
The codex has a page about using multiple loops and you’ll also want to look at the Query Posts page for information on how to limit each query to just the specific posts you want.
Thread Starter
nhall
(@nhall)
Ming,
Thank you so much for the great links. I will read up, it looks like they will be able to help with any queationa that i might have.
Thanks again
Thread Starter
nhall
(@nhall)
Here it is a month later and I am still trying to figure out the same problem. I like the two different methods that Ming discussed, but here is the question. If I incorporate a second loop, will this create problems down the road. Lets say that I get this finished and then the release an new wordpress. Will I just be able to upgrade?
As for the difference between the two methods. When you say that it can be better if the posts don’t directly follow eachother in the source code, I just want to make sure I understand. You mean that if in my layout I have a something like a div element separating the different posts, I will need two loops?
I will probably come back with some php syntax questions.
Thanks
Thread Starter
nhall
(@nhall)
I have tried to develop one loop that will display the posts differently. Here is the code that I have so far:
http://pastebin.com/383424
When I test this I get the following error:
“Parse error: parse error, expecting `'(” in /wp-content/themes/single/index.php on line 33″
Line 33 on my index.php is equal to line 15 in my pastebin.