Show Full First Post Then Excerpts In WordPress Loop
The other day someone that was using one of my free themes asked me how they could show their first post in full and then excerpts for the rest of their posts on their homepage. It had something to do with their advertising methods, but anyway after showing them how to do this I figured I would share with you the code I suggested.
Showing 1 Full Post Then Excerpts Using Counter++
The easiest way I think for achieving this effect is by adding a post counter using PHP in your loop which will “assign” an increasing number to each post in the loop (1,2,3,4,5…).
1. Add Counter
First you will want to add the counter right at the beginning of your loop:
<?php if(have_posts()) : while(have_posts()) : the_post(); $counter++; // add +1 to count for each post ?>
2. Replace the_content or the_excerpt tag
Now you’ll want to replace either the_content tag or the_excerpt tag (whichever your theme uses) so that it shows the content on the first post and then the excerpt for everything else. Following the logic below if the counter has a value of “1” it will show the full post otherwise it will show the excerpt.
<?php if($counter===1) { the_content(); } else { the_excerpt(); } ?>
Thanks a lot for your code !
I was close but didn’t managed to customize my loop until I found your article…
Worked amazing for me! Only problem was I can’t seem to get the post titles above the post and show thumbnails for the excerpted .
Worked perfect. Thanks a lot for this code cause it saves my time.
So simple, so perfect working code! Thank You AJ CLark.