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.
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; ?>
16 Responses
very nice hack! Thanks for posting this!
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!
@Cadu de Castro Alves: Exactly! Thanks for your compliments!
You can take it a step further and add only the titles for the forth, fifth, and so on, posts.
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?
@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
nice tutorial bro,
i’m very exciting
thanks brother
byme
is there a way to get those most recent posts from only a single category only???
Thanks for the post but…
How to display for example 6 excerpts posts after the 5th full post?
Regards!
@Renix:
if ($count < 6) {
the_content();
} elseif ( ($count > 6) && ($count < 12) ){
the_excerpt();
}
Thanks a lot… Very very useful!
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!!
Will this do the 1 full 3 excerpt for each page or show the same posts on each page?
Trackbacks: