





















2013-07-11 12:04 Koy 阅读(1276) 评论() 收藏 举报
這個問題我找了很多資料都沒有明說是如何解決,后來突發奇想得出我的解決方案如下,所以特此記錄一下:
object postId = blogService.NewPost(0,"admin","123456", new {
post_title = "My post 20130711",
post_content = "This is my post on 2013/07/13.",
post_status = "publish",
post_author = 1,
terms = new {category = new[]{2}}//這個 2 是我新增的一個名叫“工作日志”的分類ID
});
由于 PHP 的解決方案如下
public function create_post( $title, $body )
{
$title = htmlentities( $title, ENT_NOQUOTES, 'UTF-8' );
$content = array(
'post_type' => 'post',
'post_status' => 'pending',
'post_title' => $title,
'post_content' => $body,
'terms' => array('category' => array( 18 ) ),
'comment_status' => 'closed',
);
$params = array( 0, $this->username, $this->password, $content );
return $this->send_request( 'wp.newPost', $params );
}
我對PHP的認識只是知道它是一種面向對象的語言,其它的就一概不知了,所以我要如何將這 PHP 通過XML-RPC 轉到 C# 下用呢?
從這個問題讓我聯想到 PHP 的 array 可以是一個「對象」又是一個數組,而不象個別資料所說是 「字典類型」。實踐證明我的想法是對的,接下來就要測試發附件的功能了~~~~
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
目录:
WordPress在3.4版本中加入了XML-RPC WordPress API系列的xml-rpc函数,这里使用Python作为说明的语言,调用这套接口发布包含分组(category)或者标签(tag)内容的时候,会碰到401错误:
“抱歉,文章类型不支持您的分类法。”
对应于Wordpress源代码wp-includes/class-wp-xmlrpc-server.php中的原始错误为:
“Sorry, one of the given taxonomies is not supported by the post type.“
这个错误实际上是在调用Wordpress API时给出的分组信息错误,wp.newPost的文档中关于terms的定义是这样的:
这里两个东西的定义很隐晦,但仔细想想还是能搞定的。
Taxonomy简单来说是一种组织内容的方法,常用的taxonomy名称有
在Post的结构体中如果定义了
'terms':{'category':[4]}
则表示这篇文章的分类目录ID是4,同样,可以使用
'terms_names':{'category':["Wordpress"]}
来表示这篇文章的分类目录为Wordpress.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。