Datadial asked: “How can I display 1 full post and 3 excerpts?”

On WordPress support forum, Datadial asked how to display the full content of the most recent post, and then only posts excerpts. Let’s see how we can easily achieve this.

To achieve this, we'll use a simple WordPress loop. The only thing we have a to add is a variable (here named $count) which will count how many posts are listed.

Here's the code. Paste it instead your current WP loop and customize it a bit to make it fit your needs.

<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
  <?php if ($count < 2) : ?>
          <?php the_content() ?>
   <?php else : ?>
          <?php the_excerpt(); ?>
  <?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

18 Responses

Oct 12 2008 23:17

very nice hack! Thanks for posting this!

Oct 19 2008 00:21

This hack can be used to make a featured post page. Wrap code block with a DIV identified by an ID called, for example featured. The rest of the magic is made by CSS and, of source, by your creativity.
Useful post! Thanks!

Oct 19 2008 07:57

@Cadu de Castro Alves: Exactly! Thanks for your compliments!

Oct 25 2008 00:00

You can take it a step further and add only the titles for the forth, fifth, and so on, posts.

Oct 28 2008 21:26

Yikes! This one eludes me. I think im getting lost in the lingo, such as what is a Wordpress loop? Is it this: <?php

Also where within the post or page would the above code be inserted?

Oct 28 2008 22:27

@Missy: The WP loop is a portion of code who gets all your posts. It starts with the php instruction “while” and ends with “endwhile”.
Find the loop in your index.php file, and insert this code instead :)

Nov 02 2008 09:35

nice tutorial bro,
i’m very exciting
thanks brother
byme

Nov 08 2008 10:13

is there a way to get those most recent posts from only a single category only???

Nov 20 2008 19:45

Thanks for the post but…

How to display for example 6 excerpts posts after the 5th full post?

Regards!

Nov 20 2008 20:15

@Renix:
if ($count < 6) {
the_content();
} elseif ( ($count > 6) && ($count < 12) ){
the_excerpt();
}
:)

May 02 2009 20:29

Thanks a lot… Very very useful!

May 22 2009 04:16

Hi, I was looking for something I want to achieve with wordpress. Basically is to display 4 or 5 posts on my home page but each of them being the last posted on each category. Like showing 4 or 5 posts, each of them belonging from a particular category. I would REALLY appreciate any help on this.

Sorry for my bad english
Regards!!

Jun 19 2009 02:24

Will this do the 1 full 3 excerpt for each page or show the same posts on each page?

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required