Menu Close

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:

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.

if($counter===1) {
} else {
View Source
Posted in WordPress