WordPress – Posts As News Clips Elsewhere

Disclaimer

The instructions/steps given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.com, nor its author is responsible for any/all damage – intellectual or otherwise.

What Is The Need?

More often than not, a WordPress powered blog is (a big/small) part of a website and often times, it becomes necessary to display post-excerpts (from a diary or a journal, etc.) in the main page. This can often help visitors/readers get a glimpse of what is on offer (like a menu at a restaurant) and decide if they want to actually read it.

How To Get It Done?

Let us suppose that the website has a main page, called index.php (URL: http://www.your-site.com/index.php), and that the WordPress powered blog is served from wordpress (URL: http://www.your-site.com/wordpress/) folder. Let us suppose that we need to display the excerpts of the latest 5 posts in index.php. To that effect, let us create a file – wp_latest_posts.php – with following contents:

$post_title>
$post_date
$post_excerpt

\n”; } print ”

\n\n”; # Free up resources and close the connection to the database mysql_free_result($result); mysql_close($connect); ?>


To include this wp_latest_posts.php in index.php, one may use the following syntax at an appropriate place:

include('wp_latest_posts.php');

Screenshot

When everything goes smoothly, the result may look as follows:


wp_latest_posts