wordpress百度实时推送
按照官方的推送方法,修改适合wordpress的推送,如下代码添加到主题的functions.php
[php]
/**
* 百度主动推送
*/
if(!function_exists(‘Baidu_Submit’) && function_exists(‘curl_init’)) {
function Baidu_Submit($post_ID) {
$WEB_SITE=’www.kejianet.cn';
$WEB_TOKEN=’ZMVpCN7ZMVtenaNH';
//已成功推送的文章不再推送
if(get_post_meta($post_ID,’Baidusubmit’,true) == 1) return;
$url = get_permalink($post_ID);
$api = ‘http://data.zz.baidu.com/urls?site=’.$WEB_SITE.’&token=’.$WEB_TOKEN;
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $url,
CURLOPT_HTTPHEADER => array(‘Content-Type: text/plain’),
);
curl_setopt_array($ch, $options);
$result = json_decode(curl_exec($ch),true);
//如果推送成功则在文章新增自定义栏目Baidusubmit,值为1
if (array_key_exists(‘success’,$result)) {
add_post_meta($post_ID, ‘Baidusubmit’, 1, true);
}
}
add_action(‘publish_post’, ‘Baidu_Submit’, 0);
}
[/php]
$WEB_SITE='www.kejianet.cn'; $WEB_TOKEN='ZMVpCN7ZMVtenaNH'; 参数请前往http://zhanzhang.baidu.com/linksubmit/index修改成自己网站的参数。