How do I take an RSS feed from wordpress.com and a

2019-09-24 09:38发布

问题:

I am building a static site using php files. On the index.php file, I need to dynamically pull the RSS feed of a certain wordpress.com blog. The only information I need to pull is the excerpt content of the newest post (1 post total). When the wordpress.com blog is updated, the content on the index.php file should update to an excerpt of that newest blog post on wordpress.com.

I know how to do this with wordpress.org self-hosted blog (logging in to the wp-login.php file and adding the loop to the external index.php file), but unfortunately it doesn't work the same with wordpress.com blogs since they are automatically hosted.

回答1:

Magpie RSS is your friend. I use it a lot to grab the most recent entry via RSS an show it on another webpage. I've only used it with self-hosted Wordpress blogs, but since it's based on the RSS feed I see no reason why it wouldn't work from wordpress.com as well.

An example from their website:

require_once 'rss_fetch.inc';

$url = 'http://magpie.sf.net/samples/imc.1-0.rdf';
$rss = fetch_rss($url);

echo "Site: ", $rss->channel['title'], "<br>";
foreach ($rss->items as $item ) {
    $title = $item[title];
    $url   = $item[link];
    echo "<a href=$url>$title</a></li><br>";
}