文章评分
次,平均分 :
[收起]
文章目录
一般判断一个页面是否被百度收录都采用“site+网址”搜索命令进行检查,在这里向大家分享一下用php自动判断文章是否被百度收录的方法,并在页面没有被百度的情况下一键点击直接提交网址给百度。
将下面的代码加进主题模板文件functions.php里,然后在输出是否收录的结果信息处加入“<span><?php baidu_record(); ?></span>”即可;
PHP实现判断文章是否被百度收录
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 |
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>'; } } |

关注我的微信,获取文章更新
如果你觉得这篇文章对你有用,可以点击下面的“赞助作者”打赏作者!
转载注明原文出处:王柏元的博客>>https://wangbaiyuan.cn/php-judge-whether-baidu.html
这个方法真可能有点问题,博主你的一篇文章http://wangbaiyuan.cn/initiative-to-push-plug-in-baidu-free-link-submit-real-time.html已经被收录,但是显示未被收录。而且我发现一个现象,网上已经存在的比较多的内容容易误判为已收录。
@月儿的博客仅供参考就好,安心写好文章吧
http://blog.liren100.cn/889.html 博主你看,我这篇是没有被收录的,却显示已收录。博主能看出什么问题吗
@月儿的博客不知道咋回事呢,这个代码的原理是把模拟人去用百度搜索网址,有搜索结果表示收录。但你这篇文章收录情况的确是有问题
博主,我发现这种方法得到的结果不准确呢。有些文章没有被收录页会被认为是已经收录了。
@月儿的博客一般没有问题的啊