-
一般判断一个页面是否被百度收录都采用“site+网址”搜索命令进行检查,陈德馨在这里向大家分享一下用php自动判断文章是否被百度收录的方法,并在页面没有被百度的情况下一键点击直接提交网址给百度。
将下面的代码加进主题模板文件functions.php里,然后在输出是否收录的结果信息处加入“<span><?php baidu_record(); ?></span>”即可;
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 target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd='.get_the_title().'"><i class="fa fa-check-circle-o"></i> 已被百度收录</a>'; } else { echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'"><i class="fa fa-times"></i>未收录,点击提交</a>'; } }
WordPress中用PHP实现判断文章是否被百度收录
2243人参与 |分类: 站长百科|时间: 2013年05月07日
相关文章
- 2020-05-09WordPress使用timthumb.php截取文章缩略图
- 2018-11-09一键安装KMS服务脚本 搭建自己的KMS激活服务器教程
- 2018-10-30Windows 10系统的3D Objects(3D对象)文件夹如何删除
- 2018-03-16WINGHO..文件夹删除方法
- 2017-12-23WordPress博客什么时候才需要使用缓存插件?
- 2017-12-05WordPress站点SEO优化中需要避开6个常见错误
- 2017-11-11升级WordPress时提示’另一更新正在进行’的解决方法
- 2017-11-02WordPress上传文件自动重命名
- 2017-10-28WordPress前台显示用户的注册时间
- 2017-08-15WordPress发布/更新文章、提交/审核评论自动清理阿里云CDN缓存