0

WordPressプラグインをまとめようとしていますが、XML-RPCを介して(他のWordPressブログの)すべてのカテゴリのリストを取得したいと思います。私は次のコードを持っています、そしてそれは今のところうまくいくようです:

function get_categories($rpcurl,$username,$password){   
    $rpcurl2 = $rpcurl."/xmlrpc.php";

    $params = array(0,$username,$password,true);
    $request = xmlrpc_encode_request('metaWeblog.getCategories',$params);
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $rpcurl2);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

    $results = curl_exec($ch);
    $res = xmlrpc_decode($results);
    curl_close($ch);
    return $res;
}

使用する$resと、応答として次の文字列が返されます。Array

使用する$resultsと、次のようになります。

categoryId17 parentId0 descriptionTest categoryDescription categoryNameTest
htmlUrlhttp://test.yoursite.com/?cat=17 rssUrlhttp://test.yoursite.com/?feed=rss2&cat=17
categoryId1 parentId0 descriptionUncategorized categoryDescription
categoryNameUncategorized htmlUrlhttp://test.yoursite.com/?cat=1
rssUrlhttp://test.yoursite.com/?feed=rss2&cat=1

descriptionその後、この場合は名前を抜く必要がありますUncategorizedTest

PHPでコーディングするのは初めてです。これらの結果をページにエコーすることで取得したので、そのプロセスで変更されるかどうかはわかりません...

ちなみに、上記のコードをWordPressブログにリモートで投稿するコードから変更したので、いくつかのオプションを正しく設定していない可能性がありますか?

私が得るとvar_dump($res)

array(2) { [0]=> array(7) { ["categoryId"]=> string(2) "17" ["parentId"]=> string(1)
"0" ["description"]=> string(4) "Test" ["categoryDescription"]=> string(0) ""
["categoryName"]=> string(4) "Test" ["htmlUrl"]=> string(40)
"http://test.youreventwebsite.com/?cat=17" ["rssUrl"]=> string(54)
"http://test.youreventwebsite.com/?feed=rss2&cat=17" } [1]=> array(7) {
["categoryId"]=> string(1) "1" ["parentId"]=> string(1) "0" ["description"]=>
string(13) "Uncategorized" ["categoryDescription"]=> string(0) "" ["categoryName"]=>
string(13) "Uncategorized" ["htmlUrl"]=> string(39) "http://test.youreventwebsite.com/?cat=1"
["rssUrl"]=> string(53) "http://test.youreventwebsite.com/?feed=rss2&cat=1" } } 
4

1 に答える 1

0

配列を繰り返す必要があります。

foreach($res as $item) {
   echo $item['description'] . $item['categoryName'] . $item['htmlUrl']; //etc...

}
于 2012-10-05T09:36:05.037 に答える