这是一个非常棒的后台功能增强方式,在我们的wordpress后台列表中显示文章当前的收录情况,并且点击未被百度收录的文章,可以实现主动提交功能,高效的反馈收录状态的同时又能高效的提交解决未收录的状态。
只需要在我们的核心主题文件functions.php内添加以下代码即可成功添加百度收录情况反馈的功能,而且还有,文章id\文章图片数量、文章阅读量等多个集成数据的统计列表展现。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
/** 后台管理文章显示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:blog.mimvp.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; } } |