用户登录
还没有账号?立即注册
用户注册
点击换图
投稿取消
文章分类:
还能输入300字

上传中....

使用php发表WordPress日志

时间:2023-03-31 作者: 来源:顿格文库

谁说我们一定要登录WordPress的控制板才能发表博客日志? 利用PHP和cURL一样可以达到同样的效果, 下面就来看看吧。

我们要用下面的代码来完成任务, 不过这代码不是专为WordPress而设计的,所以请不要把代码复制到functions.php或者其它任何文件中。

注意:

一定要激活WordPress上的XMLRPC日志选项。 不激活XMLRPC,以上代码就不能在数据库中添加内容。 还有一点需要注意,php.ini文件中的XMLRPC函数也要被激活代码才能运行。

function wpPostXMLRPC($title, $body, $rpcurl, $username, $password, $category, $keywords='', $encoding='UTF-8') {

$title = htmlentities($title,ENT_NOQUOTES,$encoding);

$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);

$content = array(

'title'=>$title,

'description'=>$body,

'mt_allow_comments'=>0, // 1 to allow comments

'mt_allow_pings'=>0, // 1 to allow trackbacks

'post_type'=>'post',

'mt_keywords'=>$keywords,

'categories'=>array($category)

);

$params = array(0,$username,$password,$content,true);

$request = xmlrpc_encode_request('metaWeblog.newPost',$params);

$ch = curl_init();

curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

curl_setopt($ch, CURLOPT_URL, $rpcurl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_TIMEOUT, 1);

$results = curl_exec($ch);

curl_close($ch);

return $results;

?>

原文:Post on your WordPress blog using PHP


【★此文为顿格文库www.dunge.com文①章,不得自行转载,违者必追究!】

热门关键词