/*调用wordpress最新文章 远程调取的最新文章*/
$doc = new DOMDocument();
$doc->load( 'http://网站/blog/feed/' );
$blog_items = $doc->getElementsByTagName( "item" );
$blogs = array();
foreach( $blog_items as $key => $blog_item ){
$blog_titles = $blog_item->getElementsByTagName( "title" );
$blogs[$key]['title'] = $blog_titles->item(0)->nodeValue;
$blog_links = $blog_item->getElementsByTagName( "link" );
$blogs[$key]['link'] = $blog_links->item(0)->nodeValue;
}
$smarty->assign('blogs', $blogs);
/*调用wordpress最新文章 本地调取数据库的文章*/
$smarty->assign('blogs', index_get_new_wordpress() );
function index_get_new_wordpress() {
$sql = "SELECT ID, post_title, guid FROM wp_posts where post_status='publish' ORDER BY ID DESC LIMIT 0,9";
$res = $GLOBALS['db']->getAll($sql);
$arr = array ();
foreach ($res AS $idx => $row) {
$arr[$idx]['id'] = $row['ID'];
$arr[$idx]['title'] = $row['post_title'];
$arr[$idx]['link'] = $row['guid'];
}
return $arr;
}