WordPress的子比zibll添加判断文章是否被百度收录,图文教程,本站亲测可用

WordPress的子比zibll添加判断文章是否被百度收录,图文教程,本站亲测可用

代码简介:

很多网站的文章标题都会显示是否被百度收录,这对于站长来说非常实用,可以清楚的了解文章的收录情况。今天,我将分享一个所有会员(包括游客)都可以查看的版本。方便自己或用户知道当前文章是否被百度收录。

相关图片:

图片[1]-WordPress的子比zibll添加判断文章是否被百度收录,图文教程,本站亲测可用-凯尤木江博客圈

代码展示:

一、将以下代码添加至 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().'"><span class="but c-yellow"><i class="fa fa-paw" aria-hidden="true"></i>百度已收录</span></a>';
   } else {
        echo '<a style="color:red; rel="external nofollow"  title="一键帮忙提交给百度,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'"><span class="but c-grey"><svg class="icon" aria-hidden="true"><use xlink:href="#io-baidu1"></use></svg>百度未收录</span></a>';
   }

二、以下代码添加至自己主题页面文件适当位置,不同主题文件有所不同,子比主题在 /zibll/inc/functions/zib-single.php 文件,大概在300行左右,搜索下面代码放在下面即可。

<div class="article-content">
 
<!--百度检测收录按钮命令-->
<?php echo ' '; baidu_record(); ?>
<!--百度检测收录按钮命令-->


微信扫描下方的二维码阅读本文

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容