XML-RPC实战——获取WordPress的最新文章

In: PHPer

27 十一 2009

上回发了一篇文章介绍xmlrpc协议,今天就把他的实际应用放上来供大家学习。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
static function get_blog(){
	$url = "club.redhome.cc";
	//包含xmlrpc库
	include('xmlrpc.php');
	//指定目标编码
	$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
	$client = new xmlrpc_client("/xmlrpc.php",$url,80);
	//定义xmlrpc接口,具体可用的接口可以参考WordPress根目录下的xmlrpc.php文件
	$msg = new xmlrpcmsg('metaWeblog.getRecentPosts',
		array(
			php_xmlrpc_encode("1"),		//blog id
			php_xmlrpc_encode("admin"),		//username
			php_xmlrpc_encode("password"),		//password
			php_xmlrpc_encode("4")		//读取新闻的条数
		)
	);
	$res = $client->send($msg);
	$val = $res->value()->getval();
	$news = array();
	//取得文章的title和url
	foreach($val as $val){
		$tmp = array(
			'link' => $val['link']->getval(),
			'title' => $val['title']->getval(),
		);
		array_push($news,$tmp);
	}
	return $news;
}
?>

你可能还对以下日志感兴趣

Comment Form

About this blog

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque sed felis. Aliquam sit amet felis. Mauris semper, velit semper laoreet dictum, quam diam dictum urna, nec placerat elit nisl in quam. Etiam augue pede, molestie eget, rhoncus at, convallis ut, eros. Aliquam pharetra.

Photostream