How can I get a list of latest posts outside of my WP install?

The question:

I have a site with WP installed at /blog, and I’d like to just get a list of the latest blog posts to display on the site home page… that is to say, my custom (PHP) home page, NOT a WordPress page.

I found this, but it doesn’t work– the latest version of WordPress is looking for Translate_Entry.php or some other kind of class that it can’t find.

Is there an easy way to do this, short of picking up and parsing the RSS feed on the fly?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

You have several options.

XML-RPC

http://codex.wordpress.org/XML-RPC_Support is the place to start. The API exposes a large number of methods to access WordPress data “outside” of the full WordPress context. Difficult to setup, connection requests overhead.

wp-load.php

Include wp-load.php to load up WordPress. You will need to chdir() into WordPress first for this to work properly, depending on your environments and contexts. Easy.

chdir( 'wordpress' );
require( 'wp-load.php' );
foreach ( get_posts() as $post ) {
    echo "<h2>{$post->title}</h2>";
}

This is very similar to the link you posted. The error you’re getting is probably an include that is relative to some path. So change directories before and after.

XML feeds

Parsing the feed may be overkill, unless you cache maybe. Highly discouraged.

Method 2

there’s a slight different version of Soulseekah’s one that seems a bit better

i found it here Get user info outside WordPress


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment