How to: List recent post on a non-WordPress site

Do you ever wanted to be able to list your WordPress posts on a non-WordPress website? If yes, just read on, I got the solution to do that!

Let's go: Simply paste the following code on your non WordPress site. You may need to upload the wp-config file from the blog you want to get the posts on the same directory.

<?php
$how_many=1; //how many posts to display
require('blog1/wp-config.php'); //the path to the wp-config file of the blog I want to use
$news=$wpdb->get_results("SELECT 'ID','post_title','post_content' FROM $wpdb->posts
 WHERE 'post_type'=\"post\" AND 'post_status'=\"publish\" ORDER BY post_date DESC LIMIT $how_many"); 

foreach($news as $np){
     printf ("<div class='normalText'>%s</div>", $np->post_content);
}?>

That's all. You can also parse rss feeds, but that solution can be simpler.

One Response

Nov 09 2011 19:40

I entered the code and this is what you end up seeing on the site

get_results(“SELECT ‘ID’,'post_title’,'post_content’ FROM $wpdb->posts WHERE ‘post_type’=\”post\” AND ‘post_status’=\”publish\” ORDER BY post_date DESC LIMIT $how_many”); foreach($news as $np){ printf (”
%s
“, $np->post_content); }?>

I replaced (‘blog1/wp-config.php’) with (‘http://sodesigned.wordpress.com/wp-config.php’)

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required