Display First Full Entry And Then Following Entries As Excerpts
Posted by Nile | Posted in Tutorials | Posted on 11-20-2009 | 7 Comments
Tags: excerpt
I like to use this code to display the first full entry and then the rest of my entries as excerpts from my main page. I have used this many times, even on my other site Blondish.net. This is not hard to do and only requires that you replace a few code snippets. You can apply this to your main index template.
Look for the following code in the loop in your:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
Replace with the following.
<?php if (have_posts()) : ?>
<?php $postcount = 0; // Initialize the post counter ?>
<?php while (have_posts()) : the_post(); //start the loop ?>
<?php $postcount++; //add 1 to the post counter ?>
This code allows your blog to see how many posts you have.
2. Look for the following code. You are going to be replacing the_content
<?php the_content('Read the rest of this entry »'); ?>
with:
<?php if ($postcount == 1) : // if this is the first post ?>
<?php the_content('Read the rest of this article ->'); //Show the full post ?>
<?php else : //if this is NOT the first post ?>
<?php the_excerpt(); ?>
<?php endif; //end of the check for first post - other posts?>
The code basically tells your blog to show the first as the full entry and the following posts as excerpts.
This snippet is seen in action here at WP Addict.







