1

我们如何通过 xml-rpc 获取 wordpress 站点的类别。我现在我们需要使用用户名和传递来连接到该站点。

set_time_limit(0);
include("xmlrpc.inc"); 
$GLOBALS['xmlrpc_internalencoding'] = 'UTF-8';
define ('DOMAIN', 'abc.com'); // wordpress server
define ('BLOGID', 1); 
define ('USER', 'admin'); // wordpress admin account
define ('PASSWORD', 'pass'); // wordpress password

我将如何继续获得类别列表?

我将如何使用 wp.getCategories 类?我有这样的代码我不知道它好不好

$categories = $wp->getCategoriesEx($blogID = 1);

谢谢

4

1 回答 1

1

根据我自己的代码...

class WpXmlRpc {
    private $XmlRpcURL;
    private $UserName;
    private $PassWord;

    public function __construct($xmlrpcurl, $username, $password) {
        $this->XmlRpcURL = $xmlrpcurl;
        $this->UserName  = $username;
        $this->PassWord = $password;
    }

    private function send_request($requestname, $params) {
        $request = xmlrpc_encode_request($requestname, $params);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
        curl_setopt($ch, CURLOPT_URL, $this->XMLRPCURL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 1);
        $results = curl_exec($ch);
        curl_close($ch);
        return $results;
    }

    public function getCategories() {
        $params = array();
        return $this->send_request('wp.getCategories', $params); // your results!
    }
}

你的结果将是一个像这样的数组......

Array(
    'Request Name' => 'wp.getCategories',
    'Result' => Array(
        'category',
        'category',
        'category'
    )
于 2013-01-18T06:45:50.750 回答