Integrate wordpress with front page - just want to display the last 10 posts on index.htm

tony-raymondo

Junior Member
Joined
Jun 19, 2009
Messages
178
Reaction score
466
So i have a website with a /blog directory

I want to showcare the last 5 posts from that blog on my front page.

Anyone ever seen a little php modules / code snippets to place in the index.htm, to do this?
 
You can try the following php code that would grab the latest 5 posts directly from your wordpress database.

Note: This is only a sample code. DB info file, Modifications/Additions required to make it work as intended.

PHP:
<?php
include ('db_info.inc');
$con = mysql_connect($hostname, $dbuser, $dbpass);
$select = mysql_select_db ($selectdb, $con);
$query = "SELECT * FROM wp_posts WHERE post_status = 'publish' ORDER BY ID DESC LIMIT 5";
$result = mysql_query ($query, $con);
$number_rows = mysql_num_rows ($result);
if ($number_rows == 0)
{
$error_message = "No posts yet.";
echo ("$error_message");
}

else
{
echo ("<h2>Last 5 Blog Posts</h2>");
while ($row = mysql_fetch_array ($result))
{
// construct variables to capture post title, post content and guid (url)
// You may want to curtail the length of post content
}

echo ("
// Format the output using post title, post content and guid variables
");

}
?>
 
Last edited:
Back
Top