当我们站点发布了一些文章后,总想看看百度是否收录,经过本教程中代码实现,实时查看本文是否被百度收录,非常方便,如果你需要就按照下面代码实现吧
//WordPress添加百度文章收录情况检测
//http://www.zhidianju.com/608.html
function baidu_check($url, $post_id){
$baidu_record = get_post_meta($post_id,'baidu_record',true);
if( $baidu_record != 1){
$url='http://www.baidu.com/s?wd='.$url;
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
$rs=curl_exec($curl);
curl_close($curl);
if(!strpos($rs,'没有找到该URL。您可以直接访问') && !strpos($rs,'很抱歉,没有找到与') ){
update_post_meta($post_id, 'baidu_record', 1) || add_post_meta($post_id, 'baidu_record', 1, true);
return 1;
} else {
return 0;
}
} else {
return 1;
}
}
function baidu_record() {
global $wpdb;
$post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
if(baidu_check(get_permalink($post_id), $post_id ) == 1) {
echo '<a target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd='.get_the_title().'">百度已收录</a>';
} else {
echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'">百度未收录</a>';
}
}
添加好后还要实现调用到前端显示
<?php baidu_record(); ?>
这时功能已经集成在你网站,刷新页面查看效果吧
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.com/pt-PT/register?ref=YY80CKRN