WordPress: Display last 4 blog posts on homepage

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IanMcGreene
Forum Newbie
Posts: 1
Joined: Tue Oct 24, 2006 7:56 pm

WordPress: Display last 4 blog posts on homepage

Post by IanMcGreene »

I am wondering what the PHP code would be to display the last 4 blog posts on another page.

I have an existing homepage which links to the WP blog, but I want the last 4 posts to be displayed on the side of the homepage, just can't figure out the code to make this happen.

Thanks so much!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You are going to have to either dig into the tables or find the function the_post() and grab the SQL used in it. Then set the limit on the query to 4. Bear in mind that the app does things to the date format and the categorization. If you are just wanting the posts (without all the extra stuff) you should be able to get away with a straight query.
Post Reply