简介:一些做seo的朋友希望网站后台可以看到哪些文章是否被百度收录。小编总结了下实践原理。可以给需要的朋友参考一下。我们需要修改的是2个文件phpcms/modules/content/templates/content_list.tpl.phpphpcms/libs/func ...
一些做seo的朋友希望网站后台可以看到哪些文章是否被百度收录。小编总结了下实践原理。可以给需要的朋友参考一下。我们需要修改的是2个文件phpcms/modules/content/templates/content_list.tpl.phpphpcms/libs/functions/extention.func.php增加一个函数检测是否收录 function checkBaiduIndex($url){$url = "http://www.baidu.com/s?wd=".$url; $curl = curl_init();//注意服务器需要开启curl_init curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $rs = curl_exec($curl); curl_close($curl);$result1=preg_match_all("/没有找到该URL/", $rs, $result); //匹配成功返回ture$result2=preg_match_all("/百度为您找到相关结果约0个/", $rs, $result);//匹配成功返回tureif($result1){ $str="<font color="#444;">未收录1</font>";echo $str; }else if ($result2){ $str="<font color="#444;">未收录2</font>"; echo $str; }else{ $str="<font color="red;">收录</font>"; echo $str; }}加了2个判断,完美检测是否收录的2种情况然后后台模板文件添加调用就可以了 <th><?php echo L("title");?></th> <th>百度是否收录</th> <th width="40"><?php echo L("hits");?></th>找到title下面添加一个th然后大约在104行添加 <td align="center" class="mylist"><?php echo checkBaiduIndex($r["url"]);?></td> |