Display First WordPress Full Entry and then Following as Excerpts
Posted in WordPress | Posted on
12-30-2011 |
46 Comments
Tags: the_content, wordpress, wordpress display posts, wordpress excerpt, wordpress tricks
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. This is not hard to do and only requires that you replace a few code snippets. You can apply this to your theme’s index template file (most commonly index.php), or whatever your blog template file may be called.
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.








