Display First Full Entry And Then Following Entries As Excerpts

Posted by Nile | Posted in Tutorials | Posted on 11-20-2009 | 4 Comments

Tags:

Stumbleupon

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 &raquo;'); ?>

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.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • FriendFeed
  • Identi.ca
  • LinkedIn
  • Posterous
  • Reddit
  • StumbleUpon
  • Technorati
  • Tumblr
  • Twitter
  • Yahoo! Buzz

Related posts:

  1. Edit This Entry Template Tag
  2. Canonicalization in Your WordPress Blog
  3. Disable Comments For Older Posts

Comments (4)

Nile:

For those of us who are not comfortable with replacing code what else do you suggest to accomplish your excellent idea?

Thanks,

Rob

If you prefer not using the code and instead trying a plugin, http://wordpress.org/extend/plugins/tags/excerpt has a few that you can choose between to make your excerpts. The only thing is that it does not do the first full article and then the following ones as excerpts. I will have to find a way to make a plugin that does this where you can choose what type and how many characters, or even lines.

Thank you for this, it does exactly what I needed.
Kim @ What’s That Smell?´s last blog ..(ENDED) Sam’s Club, Skinny Cow and $500 (GIVEAWAY) My ComLuv Profile

I am really glad this worked for you. :)

Write a comment

CommentLuv Enabled