WordPress 通过API提交内容到熊掌号

WordPress 通过API提交内容到熊掌号

当我们每次发布新的内容的时候,后台自动就会提交到熊掌号,免得我们每次都要自己手动提交了
在主题的 function.php 中加入:
直接上代码:

Python
/** * WordPress API 方式自动推送到百度熊掌号* */ if(!function_exists('Baidu_XZH_Submit')){ function Baidu_XZH_Submit($post_ID) { //已成功推送的文章不再推送 if(get_post_meta($post_ID,'BaiduXZHsubmit',true) == 1) return; $url = get_permalink($post_ID); $api = 'http://data.zz.baidu.com/urls?appid=你的APPID&token=你的TOKEN&type=realtime'; $request = new WP_Http; $result = $request->request( $api , array( 'method' => 'POST', 'body' => $url , 'headers' => 'Content-Type: text/plain') ); $result = json_decode($result['body'],true); //如果推送成功则在文章新增自定义栏目BaiduXZHsubmit,值为1 if (array_key_exists('success',$result)) { add_post_meta($post_ID, 'BaiduXZHsubmit', 1, true); } } add_action('publish_post', 'Baidu_XZH_Submit', 0); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/ * *
*    WordPress API 方式自动推送到百度熊掌号 *
* /
if ( ! function_exists ( 'Baidu_XZH_Submit' ) ) {
     function Baidu_XZH_Submit ( $ post_ID ) {
         / /已成功推送的文章不再推送
         if ( get_post_meta ( $ post_ID , 'BaiduXZHsubmit' , true ) == 1 ) return ;
         $ url = get_permalink ( $ post_ID ) ;
         $ api = 'http://data.zz.baidu.com/urls?appid=你的APPID&token=你的TOKEN&type=realtime' ;
         $ request = new WP_Http ;
         $ result = $ request -> request ( $ api , array ( 'method' = > 'POST' , 'body' = > $ url , 'headers' = > 'Content-Type: text/plain' ) ) ;
         $ result = json_decode ( $ result [ 'body' ] , true ) ;
         / /如果推送成功则在文章新增自定义栏目 BaiduXZHsubmit,值为 1
         if ( array_key_exists ( 'success' , $ result ) ) {
             add_post_meta ( $ post_ID , 'BaiduXZHsubmit' , 1 , true ) ;
         }
     }
     add_action ( 'publish_post' , 'Baidu_XZH_Submit' , 0 ) ;
}
 

百度后台反馈




  • zeropython 微信公众号 5868037 QQ号 5868037@qq.com QQ邮箱
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值