之前也弄过类似的,但那是很久之前的了,因为以前使用的服务器是很小很小的。从服务的性能方面考虑,所以最后就放弃了。
现在想了一下,也是用不到太大的内存资源,所以加一个能实时观测到网站的收录情况,所以也就添加一个。
效果演示:
所需代码:
// 检测网页是否收录 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 style="color:green;" target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd='.get_the_title().'">已收录</a>'; } else { echo '<a style="color:red;" rel="external nofollow" title="一键帮忙提交给百度,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'">未收录</a>'; } }
其他说明:
把上面的代码放到wordpress程序的模板下的 functions.php 文件里面,之后在需要添加这个功能的网页的中添加下面的php代码,建议是放在文章内容页面进行展示。
<?php baidu_record(); ?>