wordpress纯代码的文章百度收录状态检测与显示

wordpress纯代码的文章百度收录状态检测与显示 | JUST FOR FUN
以下代码添加到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='https://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 '已收录';
    } else {
    echo '未收录';
    }
    }

调用方法

添加到文章模板(一般是single.php)合适地方!
转自 https://www.9yo.cc/1340.html

Wp插件

腾讯万象优图WordPress插件

2015-8-27 17:15:33

Wp插件

自动将中文标题翻译为英文插件-WP Slug Translate

2015-10-10 14:27:03

个人中心
今日签到
有新私信 私信列表
搜索