Displaying the whole content of the latest post and excerpt for the rest, in WordPress

Knowledge Base on June 30th, 2010 Comments Off

This post was originally published at LionVineyard.com on 2009/02/27

Recently I was struggling how to display the posts on the main page of one of the blogs I am administering. Displaying the whole content of posts was making the main page too long, displaying only the summary was making the main page kind of dull as it was missing the pictures.

The problem:

Display the whole content of the first post and summary for the rest.

The post display on the main page is controlled by the infamous The Loop. In order to achieve this The Loop has to be tempered.

I did some search but could not find something that would solve my problem so I decided to go with my instinct which is greatly influenced by my Fortran background.

A typical The Loop that displays the whole content looks like this:


//commands to display title, author, date, here


// some message here if no posts are found

The the_content() function can be replaced by the_excerpt() function to display the summary.

The solution:
Define a numeric variable within the if loop, and increment it within the while loop. In this case the variable is x. The new The Loop looks like this:


//commands to display title, author, date, here


// some message here if no posts are found

So the above implementation should display the whole content of the first post and the summary of the rest.
If you have any suggestions that are more PHP friendly or even WordPress friendly in achieving this please leave your comments below…

Comments are closed.
RSS Feed
on facebook
@twitter
footer