Is there plugin to show recent posts from one website in the widget area of another?

I would like to take the titles of recent posts or content related posts from one website and display them in the widget area of another website. I’m sure there must be a way to do this, perhaps some adaptation to the standard ‘recent posts’ widget?

I did something similar before using an rss feed from one site and displaying their titles in a module on another. However this was in a non-wordpress site and I am not quite sure how to achieve the same result here.

Read More

Ideally I would like to do it without using an rss feed and also be able to control specifically which posts are shown, perhaps being able to define them manually or by other criteria than just ‘recent’.

Related posts

Leave a Reply

1 comment

  1. There are three ways you can accomplish this: two are very code intensive, the other is already built-in.

    RSS

    Hand’s down, the easiest way to do what you want to do is with an RSS widget. WordPress already has an RSS widget built-in to core, so all you need to do is specify the feed and voila!

    The widget displays the title by default, but you can also add the post’s content, author, and publication date. Tweaking the front-end display to fit your layout is left up to CSS, just like any other widget.

    This method doesn’t require you to have access to the other site at all and (other than styling the CSS) doesn’t require any coding whatsoever.

    alt text

    Custom Code

    If you have direct database access (which you say yo do), you can add a script to the one site that loads content from the other. You can do this one of two ways:

    • Include the WordPress bootstrap file (wp-blog-header.php) and load up WordPress within the second site. Then you can use the standard WordPress query functions to retrieve posts and do with them whatever you want.
    • Use direct database queries to quickly pull information out of the database. You’re looking at the wp_posts table for anything with post_type=post and post_status=publish. Just get the title and content, then do whatever you need to do.

    I actually used this method on a client site. They had an existing PHP/MySQL-driven home page and wanted to add links to an external WordPress blog. If you go to their site, you’ll see a list of blog posts on the front page – the front page is generated by a proprietary CMS that queries the WordPress database to find, parse, and display a list of recent posts.

    XML-RPC

    WordPress has a fantastic XML Remote Procedure Call system built-in to core. This system allows for external applications (desktop applications, iPhone apps, other websites) to remotely interact with WordPress by sending and receiving XML-formatted messages. There’s even an XML-RPC method that does exactly what you want: metaWeblog.getRecentPosts.

    So, turn XML-RPC ‘on’ for the site you want to request posts from. Then send a metaWeblog.getRecentPosts request to http://yoursite.com/xmlrpc.php that specifies the following parameters:

    • ID of the blog you’re working with (usually 0 for a single site)
    • WordPress username
    • WordPress password
    • Number of posts you want to return

    WordPress will log you in, run a query to fetch the posts, and return an XML object containing a list of recent posts (as many as you specified) that each contain the following:

    • dateCreated – Post publication date
    • userid – ID of the post author
    • postid – ID of the post itself
    • description – Post content
    • title – Post title
    • link – Post permalink
    • permaLink – Post permalink
    • categories – Array of post categories
    • mt_excerpt – Post excerpt
    • mt_text_more – Read More text
    • mt_allow_comments – Whether comments are open or closed
    • mt_allow_pings – Whether pings are open or closed
    • mt_keywords – Array of post tags
    • wp_slug – Post slug
    • wp_password – Post password
    • wp_author_id – ID of the post author
    • wp_author_display_name – Display name of the post author
    • date_created_gmt – Post publication date (as GMT time)
    • post_status – Post publication status
    • custom_fields – Array of custom fields
    • sticky – Whether or not the post is marked as “sticky”

    I wrote a tutorial specific to the MetaWeblog API (which is implemented by WordPress) some time ago. I’ve also written one that explains how to use the XML-RPC API from within WordPress to make calls to an external WordPress system. That might help to get you started.

    If you want to fetch a specific post rather than just “recent” posts, there’s a method call for that, too. Just call metaWeblog.getPost and specify the ID of the post you want and your WordPress username and password. This method will return a single post as an XML object containing the same data as I listed above.