You can do that all in one loop.. you only need a counter, to determine where you are in the loop..
Example snippet of code:
// If the query has posts
if( have_posts() ) :
// Create a counter variable
$counter = 0;
// While there are posts, aka The Loop
while( have_posts() ) : the_post();
// Increment the counter in each iteration of a post, by +1
$counter++;
// other regular loop stuff
// If the counter is 1 or 5, then show full content
if( $counter == 1 || $counter == 5 ) {
the_content();
}
// Else show an excerpt
else {
the_excerpt();
}
// End loop
endwhile;
// End if have posts
endif;
Alternatively you can check some of the previous threads asking similar questions.
http://wordpress.org/search/first+post+full+second+excerpt?forums=1
The code involved is usually the same, so don’t worry too much about the search terms i used above.
Thread Starter
phobic
(@phobic)
many thanks for the response t31os_, the only problem is that the PHP code and CSS is completely different for each different section – some include the title, some don’t, some show images and custom fields, some don’t. I’m fairly certain I need to begin with three separate loops, though I might be wrong..
No you don’t need extra loops, you just conditionalise everything in the same way i’ve done it in the example above..
Here’s an example of conditions used to control the elements.
<?php if( $counter == 3 ) { ?>
<div class="mydiv-first">
<h3><?php the_title() ?><h3>
<?php the_content() ?>
</div>
<?php } elseif( $counter == 5 ) { ?>
<div class="mydiv-somethingelse">
<div class="someother">
<?php the_title() ?>
</div>
<?php the_excerpt() ?>
</div>
<?php } ?>
That could be extended to do any number of things.
Hope that helps..
Thread Starter
phobic
(@phobic)
hrm.. that would certainly be much cleaner than separate loops. many thanks t31os_, I’ll give this a try!