将下面的代码添加到主题的 functions.php

    1. function ribs_baidu_check($url) {
    2. global $wpdb;
    3. $post_id = (null === $post_id) ? get_the_ID() : $post_id;
    4. $baidu_record = get_post_meta($post_id, 'ribs_baidu_record', true);
    5. if ($baidu_record != '收录') {
    6. $url = 'http://www.baidu.com/s?wd=' . $url;
    7. $curl = curl_init();
    8. curl_setopt($curl, CURLOPT_URL, $url);
    9. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    10. $rs = curl_exec($curl);
    11. curl_close($curl);
    12. if (!strpos($rs, '没有找到')) {
    13. if ($baidu_record == '未收录') {
    14. update_post_meta($post_id, 'ribs_baidu_record', '收录');
    15. } else {
    16. add_post_meta($post_id, 'ribs_baidu_record', '收录', true);
    17. }
    18. return '收录';
    19. } else {
    20. if ($baidu_record == false) {
    21. add_post_meta($post_id, 'ribs_baidu_record', '未收录', true);
    22. }
    23. return '未收录';
    24. }
    25. } else {
    26. return '收录';
    27. }
    28. }
    29. function ribs_baidu_record() {
    30. if (ribs_baidu_check(get_permalink()) == '收录') {
    31. echo '<a target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd=' . get_the_title() . '" >收录</a>';
    32. } else {
    33. echo '<a rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename=' . get_permalink() . '" >未收录</a>';
    34. }
    35. }

    在网页适当位置添加

    <?php ribs_baidu_record(); ?>
    

    你不希望所有人看到的话,加上一个判断登陆人权限的代码

    <?php if (current_user_can('level_10')){ribs_baidu_record();}; ?>
    

    想要在后台,看见的话,在 functions.php 里加

    //后台文章管理列表显示收录情况
    add_filter('manage_posts_columns', 'my_add_posts_columns', 5);
    add_action('manage_posts_custom_column', 'my_custom_posts_columns', 5, 2);
    function my_add_posts_columns($defaults) {
        $defaults['ribs_baidu_record'] = '百度收录';
        return $defaults;
    }
    function my_custom_posts_columns($column_name, $id) {
        if ($column_name === 'ribs_baidu_record') {
            echo get_post_meta(get_the_ID(), 'ribs_baidu_record', true);
        }
    }