How do I take an RSS feed from wordpress.com and add the newest post of the feed to another website? [closed]

我们两清 提交于 2019-12-13 09:21:33

问题


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>";
}


来源:https://stackoverflow.com/questions/3129937/how-do-i-take-an-rss-feed-from-wordpress-com-and-add-the-newest-post-of-the-feed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!