网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   Blog(博客)/Wiki(维客)/RSS/Cms (https://www.0058.net/forumdisplay.php?f=17)
-   -   外部网站如何调用WordPress文章? (https://www.0058.net/showthread.php?t=4115)

topvip 2010-06-18 07:02 PM

外部网站如何调用WordPress文章?
 
利用第三方RSS and Atom Feed Framework调用WordPress
我使用的是这种方法,好处是调用代码是静态的,而非HTML代码。步骤如下,下载SimplePie Plugin for WordPress或者下载SimplePie最新版,将“simplepie.inc”上传到主机相应的目录,然后在需要调用的地方粘贴下面的代码即可(以万戈的Rss地址为例)。
<?php
require_once('simplepie.inc');
$feed = new SimplePie();
$feed->set_feed_url('http://www.glassesdaily.com/feed');
$feed->init();
echo '<ul>';
$i = 1;foreach($feed->get_items() as $item){
if($i<15){
echo '<li><a href="'.$item->get_permalink().'">'.$item->get_title().'</a><br />'. "\n";
echo substr($item->get_description(),0,180).'...</li>'."\n";
$i++; }}
echo '</ul>';
?>

当然,可以根据自己的需要修改这个代码的。


All times are GMT +8. The time now is 10:54 AM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.