WordPress纯代码添加判断当前文章是否被百度收录

午夜时分给大家分享WordPress纯代码判断当前文章是否被百度收录代码,非管理员也能发看得见,方便自己或用户知道当前文章是否被百度收录.

WordPress纯代码添加判断当前文章是否被百度收录

方法/步骤

一、将以下代码添加至functions.php;

  1. //判断文章是否被百度收录
  2. function baidu_check($url){
  3.     global $wpdb;
  4.     $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
  5.     $baidu_record  = get_post_meta($post_id,'baidu_record',true);
  6.     if$baidu_record != 1){
  7.         $url='http://www.baidu.com/s?wd='.$url;
  8.         $curl=curl_init();
  9.         curl_setopt($curl,CURLOPT_URL,$url);
  10.         curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
  11.         $rs=curl_exec($curl);
  12.         curl_close($curl);
  13.         if(!strpos($rs,'没有找到')){
  14.             if$baidu_record == 0){
  15.                 update_post_meta($post_id, 'baidu_record', 1);
  16.             } else {
  17.                 add_post_meta($post_id, 'baidu_record', 1, true);
  18.             }
  19.                 return 1;
  20.         } else {
  21.             if$baidu_record == false){
  22.                 add_post_meta($post_id, 'baidu_record', 0, true);
  23.             }
  24.             return 0;
  25.         }
  26.     } else {
  27.        return 1;
  28.     }
  29. }
  30. function baidu_record() {
  31.     if(baidu_check(get_permalink()) == 1) {
  32.         echo '<a target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd='.get_the_title().'"><font color="#ff0000">百度已收录</font></a>';
  33.    } else {
  34.         echo '<a style="color:#c40000; rel="external nofollow"  title="提交链接" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'"><font color="#ff0000">百度未收录</font></a>';
  35.    }
  36. }

二、以下代码添加至自己主题页面文件适当位置,不同主题文件有所不同,Begin Lts主题在/template目录下的content.php文件,大概在101行左右,搜索【<div class="single-content">】,放在<div class="single-content">下面即可.

  1. <center><?php baidu_record(); ?></center>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索