如何在wordpress后台文章列表中添加百度收录情况

这是一个非常棒的后台功能增强方式,在我们的wordpress后台列表中显示文章当前的收录情况,并且点击未被百度收录的文章,可以实现主动提交功能,高效的反馈收录状态的同时又能高效的提交解决未收录的状态。

只需要在我们的核心主题文件functions.php内添加以下代码即可成功添加百度收录情况反馈的功能,而且还有,文章id\文章图片数量、文章阅读量等多个集成数据的统计列表展现。

/** 后台管理文章显示ID **/
/**********文章添加自定义列***********/
add_filter('manage_posts_columns', 'add_postid_posts_columns');   
function add_postid_posts_columns($book_columns) {   
    $new_columns['cb'] = '<input type="checkbox" />';   
    $new_columns['id'] = __('ID');   
    $new_columns['title'] = _x( 'Title', 'column name' );   
    $new_columns['images'] = __( 'Images');   
    $new_columns['author'] = __('Author');   
    $new_columns['categories'] = __('Categories');   
    $new_columns['tags'] = __('Tags');   
    $new_columns['date'] = _x('Date', 'column name');   
    $new_columns['comments'] = _x('评论', 'column name');   
    $new_columns['views'] = _x('Views', 'column name');   
    $new_columns['baidu_record'] = _x('百度收录', 'column name');   
    return $new_columns;   
}   
add_action('manage_posts_custom_column', 'manage_book_columns', 10, 2);   
function manage_book_columns($column_name, $id) {   
    global $wpdb;   
    switch ($column_name) {   
    case 'id':   
        echo $id;   
        break;   
  
    case 'images':    
        $num_images = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->posts WHERE post_parent = {$id};"));   
        echo $num_images;    
        break;   
  
    case 'baidu_record':    
        $baidu_record = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = {$id} and meta_key = 'baidu_record';"));   
        @$record_url='http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink();
        @$result="<a style='color:red;' target='_blank' href=\"$record_url\">未收录</a>";
        if($baidu_record=="1") {
//            echo $baidu_record;    
//            echo "是";
            $record_url='http://www.baidu.com/s?wd=sitemap:www.555558555.com '.get_the_title();
            @$result="<a style='color:blue;' target='_blank' href=\"$record_url\">已收录</a>";
        }
        echo $result;
        break;
    default:
        break;
    }
}
  
/**************页面添加自定义列************/
add_filter('manage_pages_columns', 'add_new_pages_columns');
function add_new_pages_columns($book_columns) {
    $new_columns['cb'] = '<input type="checkbox" />';
    $new_columns['id'] = __('ID');
    $new_columns['title'] = _x( 'Title', 'column name' );
    $new_columns['author'] = __('Author');
    $new_columns['date'] = _x('Date', 'column name');
    $new_columns['comments'] = _x('评论', 'column name');
    $new_columns['views'] = _x('Views', 'column name');
    return $new_columns;
}
add_action('manage_pages_custom_column', 'manage_pages_columns', 10, 2);
function manage_pages_columns($column_name, $id) {
    global $wpdb;
    switch ($column_name) {
    case 'id':
        echo $id;
        break;
    default:
        break;
    }
}

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。[本站由 WEEX唯客交易所(官网www.weex.com,备用域名www.weex.sh)提供赞助]