分享
也是一种美德

WordPress自动检测文章是否被百度收录并提交到百度代码版

第一:将代码添加到当前主题Functions.php文件中。

function baidu_check($url){
global $wpdb;
$post_id = ( null === $post_id ) ? get_the_ID() : $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,’没有找到’)){
if( $baidu_record == 0){
update_post_meta($post_id, ‘baidu_record’, 1);
} else {
add_post_meta($post_id, ‘baidu_record’, 1, true);
}
return 1;
} else {
if( $baidu_record == false){
add_post_meta($post_id, ‘baidu_record’, 0, true);
}
return 0;
}
} else {
return 1;
}
}
function baidu_record() {
if(baidu_check(get_permalink()) == 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(); ?>

在需要显示的当前文章页面single.php标题下面就可以看到。

赞(0) 打赏
未经允许不得转载:宇峰博客 » WordPress自动检测文章是否被百度收录并提交到百度代码版
分享到: 更多 (0)

评论 5

  1. #1

    Canadian Pharmacy Express Cialis Cuanto Dura Propecia Malattia viagra Cialis Femminile

    匿名1个月前 (05-04)回复
  2. #2

    Cialis Comparatif Prix cialis no prescription First Medicine Online Pharamacy Store Cialis Forum Alfemminile Keflex And Utis

    匿名1周前 (06-06)回复
  3. #3

    Cialis 10 Mg Directions viagra Mountainwest Apothecary Buy 10 Mg Levitra Online

    匿名1周前 (06-07)回复
  4. #4

    Acheter Cialis Pharmacie France Keflex Prostate Infection Dog cialis 20mg price at walmart Viagra Salud

    匿名1天前回复
  5. #5

    Sildenafil Citrate 100mg Prices Amoxicillin Chewable Peppermint Tablets Ingredients 100mg Viagra Cost Per Pill 114 viagra online prescription Amoxicillin Dogs Long Term Useage Tumors Dosage Cephalexin Zithromax Feel Worse

    匿名1小时前回复

宇峰博客 分享也是一种美德

我的微博我的博客

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏