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

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x