Display Full First Post & Excerpts in WordPress Loop

How to Show First Post in Full and Excerpts for the Rest on Your Homepage

If you’re looking to display your first post in full and then show excerpts for the rest of your posts on your homepage, you’re in luck. This effect can be achieved easily by adding a post counter using PHP in your loop. The counter will assign an increasing number to each post in the loop, allowing you to display the first post in full and then show excerpts for the rest.

Here’s how to do it:

Step 1: Add Counter

The first step is to add the counter right at the beginning of your loop. You can do this by adding the following code:

“`

if(have_posts()) : while(have_posts()) : the_post();

$counter++; // add +1 to count for each post

?>

“`

This code will create a loop that goes through each post and adds a counter that increases by one for each post.

Step 2: Replace the_content or the_excerpt Tag

Next, you’ll want to replace either the_content tag or the_excerpt tag (whichever your theme uses) so that it shows the content on the first post and then the excerpt for everything else. You can do this by adding the following code:

“`

if($counter===1) {

the_content();

} else {

the_excerpt();

}

?>

“`

This code checks if the counter has a value of “1”. If it does, it shows the full content of the post. If it doesn’t, it shows an excerpt of the post.

By following these two steps, you can easily display your first post in full and then show excerpts for the rest of your posts on your homepage. This is a great way to highlight your most important content while still giving your readers a taste of what else you have to offer.

Why Use This Method?

There are several reasons why you might want to use this method to display your posts on your homepage. Here are a few:

1. Highlight Your Best Content

By displaying your first post in full, you can highlight your best content and draw attention to it. This is a great way to get readers interested in what you have to say and keep them coming back for more.

2. Improve Readability

Excerpts are a great way to improve the readability of your homepage. By showing only a short summary of each post, you can make it easier for readers to scan your content and find what they’re looking for.

3. Increase Pageviews

By showing only excerpts for your other posts, you can encourage readers to click through to read the full post. This can increase your pageviews and help you build a larger audience.

Overall, this method is a great way to improve the look and feel of your homepage while still giving your readers easy access to all of your content. Give it a try and see how it works for you!

Stay in Touch

spot_img

Related Articles