WordPress主题增加文章添加百度收录情况的方法

很多站点上都添加了检测百度是否收录的功能,对网站内容是否收录的管理,同时可以更加亲密地与访客进行交互。

方法一:

下面只需一段代码即可随时了解百度收录情况,并提供提交百度入口,以加速百度收录下面只需一段代码即可随时了解百度收录情况,并提供提交百度入口,以加速百度收录

//百度收录提示
if (git_get_option('git_baidurecord_b') && function_exists('curl_init')) {
    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 title="" rel="external nofollow" target="_blank" href="https://www.pieruo.com/wp-content/themes/begin/go.php?url=aHR0cHM6Ly93d3cuYmFpZHUuY29tL3M/d2Q9Jzwvc3Bhbj48c3BhbiBjbGFzcz0="crayon-h"> . get_the_title() . '" target="_blank"
rel="external nofollow" data-original-title="点击查看">已收录</a>';
        } else {
            echo '<a style="color: red;" title="" rel="external nofollow" target="_blank" href="https://www.pieruo.com/wp-content/themes/begin/go.php?url=aHR0cDovL3poYW56aGFuZy5iYWlkdS5jb20vc2l0ZXN1Ym1pdC9pbmRleD9zaXRlbmFtZT0nPC9zcGFuPjxzcGFuIGNsYXNzPQ=="crayon-h"> . get_permalink() . '" target="_blank"
rel="external nofollow" data-original-title="点击提交,谢谢您!">未收录</a>';
        }
    }
}

上面的函数式放在主题 functions 文件中,然后在文章内容页面适合地方加入下方这段代码

<?php if (git_get_option('git_baidurecord_b') && function_exists('curl_init')) { ?><span class="muted"><i class="fa fa-flag"></i> <?php
baidu_record(); ?></span>

方法二:

/* 检查百度是否已收录文章页面 管理员可以见 */
function d4v($url)
{
    $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, '没有找到')) {
        return 1;
    } else {
        return 0;
    }
}
add_filter('the_content', 'baidu_submit');
function baidu_submit($content)
{
    if (is_single() && current_user_can('manage_options')) {
        if (d4v(get_permalink()) == 1) {
            echo '<p align=right><b><a target="_blank" title="点击查看" rel="external nofollow" rel="external nofollow" target="_blank" href="https://www.pieruo.com/wp-content/themes/begin/go.php?url=aHR0cHM6Ly93d3cuYmFpZHUuY29tL3M/d2Q9JyAuIGdldF90aGVfdGl0bGUoKSAuICc=">此文章已被百度收录</a></b>(仅管理员可见)</p>';
        } else {
            $content = "<p align=right><b><a style=color:red target=_blank href=https://zhanzhang.baidu.com/sitesubmit/index?sitename=" . get_permalink() . ">百度未收录!点击此处一键提给百度交</a></b>(仅管理员可见)</p>" . $content;
        }
    }
    return $content;
}

以上2种版本可根据个人喜好以及主机实际情况选择一个即可!

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享
评论 抢沙发

请登录后发表评论