需要一个代码示例显示如何发布到Wordpress使用Codeigniter [英] Need a code sample showing how to post to Wordpress using Codeigniter
本文介绍了需要一个代码示例显示如何发布到Wordpress使用Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人有一个代码示例,他们可以共享,显示如何使用CodeIgniter xml-rpc库的Wordpress基本的博客帖子?
Does anyone have a code sample they can share that show how to make a basic blog post to Wordpress using the CodeIgniter xml-rpc library?
到目前为止,我有这个,这总是导致坏登录/通过组合,虽然我使用正确的组合。
So far, I have this, which always results in "Bad login/pass combination", although I am using the correct combination.
function doPost(){
$this->load->library('xmlrpc');
$bloguser = "theUserid";
$blogpass = "thePassword";
$blogid = 0; //I've tried 0 and 1 here.
$post['title'] = "The title of a new post";
$post['description'] = "The body of the post.";
$this->xmlrpc->server("http://localhost/blog/xmlrpc.php", 80);
$this->xmlrpc->method('metaWeblog.newPost');
$this->xmlrpc->request = array($blogid, $bloguser, $blogpass, $post, TRUE);
if ( ! $this->xmlrpc->send_request())
{
echo $this->xmlrpc->display_error();
}
else
{
echo '<pre>';
print_r($this->xmlrpc->display_response());
echo '</pre>';
}
}
推荐答案
很多咬牙,这似乎工作:
After much gnashing of teeth, this seems to work:
function doPost(){
$this->load->library('xmlrpc');
$bloguser = "theUserID";
$blogpass = "thePassword";
$blogid = 1;
$publishImmediately = TRUE;
$thePost = array(array('title' => array('this is the title','string'),
'description' => array('this is the description','string')
),
'struct');
$myPost = "my post";
//$this->xmlrpc->set_debug(TRUE);
$this->xmlrpc->server("http://url.to/xmlrpc.php", 80);
$this->xmlrpc->method('metaWeblog.newPost');
$request = array($blogid, $bloguser, $blogpass, $thePost, $publishImmediately);
$this->xmlrpc->request($request);
$result = $this->xmlrpc->send_request();
if ( !$result )
{
echo $this->xmlrpc->display_error();
}
else
{
echo '<pre>';
print_r($this->xmlrpc->display_response());
echo '</pre>';
}
}
重要的是注意元素的结构的实际职位。
The important part is to note the struct for the elements of the actual post.
这篇关于需要一个代码示例显示如何发布到Wordpress使用Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文