Display First Full Entry And Then Following Entries As Excerpts

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

Tags:

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. Display Posts From A Category In WordPress
  2. Edit This Entry Template Tag
  3. Creating A Simple Author Profile Page In WordPress
  4. How to Display A User Welcome Message In WordPress
  5. Canonicalization in Your WordPress Blog

About Nile Flores

Web and graphic designer fom Southern Illinois. I love to work with WordPress.

Connect with Nile at: Twitter | Facebook | LinkedIn

Nile has written 87 articles at WPAddict.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Comments (7)

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) =-.

I am really glad this worked for you. :)

Brilliant! Just what I was looking for.
Thank you for your most helpful website :-)

No problem! I am glad to be of some help. If you have any WordPress questions you can ask… might even answer it in a post. :D

I am using this code and it works…however it displays the first post on every page as full …i.e my home page displays at most 10 posts, so by using "next page" the 20th post is full with 21 and so on as excerpts…anyway to add to this code so that it is only the "Latest Post" showed as full on the home page?