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

2022-08-08 0 566

教程解读:

分享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().'" rel="external nofollow" ><font color="#ff0000">百度已收录</font></a>';
   } else {
        echo '<a style="color:#c40000; rel="external nofollow"  title="提交链接" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'" rel="external nofollow" ><font color="#ff0000">百度未收录</font></a>';
   }

第二,将以下代码添加到您自己的主题页面文件的适当位置。不同的主题文件是不同的。/template 目录中的 content.php 文件大约有 101 行。只需搜索[]放在下面。

<center><?php baidu_record(); ?></center>

 

 

教程

截图

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

转载请注明:汇站网 » WordPress 纯代码添加判断当前文章是否被百度收录

收藏 (0)

微信支付 微信扫一扫

支付宝支付 支付宝扫一扫

点赞 (0)

站长资源下载中心-找源码上汇站

常见问题
  • 如果付款后没有弹出下载页面,多刷新几下,有问题联系客服!
查看详情
  • 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
查看详情

相关文章

联系官方客服

为您解决烦忧 - 24小时在线 专业服务