百度,360,搜狗,等等一系列中文搜索引擎,都知道百度是最常用的吧!用下面的代码,打开文章就能看见百度是否收录了该文章。
只是检测文章收录情况,并不能SEO,效果可以看本站!

EMLOG

1,打开主题下module.php文件,添加以下代码到相应位置

<?php
//判断内容页是否百度收录
function checkBaiduInclude($url){
 $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,'没有找到')){
 return 1;
 }else{
 return 0;
 }
}
function logurl($id){
 $url=Url::log($id);
 if(checkBaiduInclude($url)==1){
 echo "<a rel='external nofollow' href='http://www.baidu.com/s?wd=$url' title='点击查看收录详情' target='_blank'>百度已收录,详情</a>";
 }else{
 echo "<a style=\"color:red;\" rel=\"external nofollow\" title=\"点击提交收录,谢谢!\" target=\"_blank\" href=\"http://zhanzhang.baidu.com/sitesubmit/index?sitename=$url\">百度未收录,提交</a>";
 }
}
?>

2,打开主题下echo_log.php文件,添加挂载点到需要显示的位置

<?php echo logurl($logid); ?>

WordPress

1,打开主题下functions.php文件,添加以下代码到最底部的 ?> 前面

//判断内容页是否百度收录
function baidu_check($url, $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,'没有找到该URL。您可以直接访问') && !strpos($rs,'很抱歉,没有找到与') ){
 update_post_meta($post_id, 'baidu_record', 1) || add_post_meta($post_id, 'baidu_record', 1, true);
 return 1;
 } else {
 return 0;
 }
 } else {
 return 1;
 }
}
function baidu_record() {
 global $wpdb;
 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
 if(baidu_check(get_permalink($post_id), $post_id ) == 1) {
 echo '<a target="_blank" title="点击查看收录详情" rel="external nofollow" rel="external nofollow" target="_blank" href="https://www.9ywk.com/wp-content/themes/begin/go.php?url=aHR0cDovL3d3dy5iYWlkdS5jb20vcz93ZD0nLmdldF90aGVfdGl0bGUoKS4n">百度已收录,详情</a>';
 } else {
 echo '<a style="color:red;" rel="external nofollow" title="点击提交收录!" target="_blank" rel="external nofollow" target="_blank" href="https://www.9ywk.com/wp-content/themes/begin/go.php?url=aHR0cDovL3poYW56aGFuZy5iYWlkdS5jb20vc2l0ZXN1Ym1pdC9pbmRleD9zaXRlbmFtZT0nLmdldF9wZXJtYWxpbmsoKS4n">百度未收录,提交</a>';
 }
}

2,打开主题下single.php文件,添加挂载点到需要显示的位置

<?php baidu_record(); ?>

Typecho

1.打开主题下functions.php文件,添加以下代码到最底部的 ?> 前面

/*typecho文章百度是否收录*/
function baidu_record() {
$url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

if(checkBaidu($url)==1)
{echo "<a rel='external nofollow' href='http://www.baidu.com/s?wd=$url' target='_blank'>已收录,详情</a>";
}
else
{echo "<a target=\"_blank\" 
href=\"http://zhanzhang.baidu.com/sitesubmit/index?sitename=$url\">未收录,点击提交</a>";}
}
function checkBaidu($url) {
$url = 'http://www.baidu.com/s?wd=' . urlencode($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, '没有找到')) { //没有找到说明已被百度收录
return 1;
} else {
return -1;
}
}

2.在主题下文章页面post.php里合适位置,添加挂载到需要显示的位置

<span>百度收录:<?php echo baidu_record() ?></span>

  • 代码来源于网络,typecho效果可看本站文章底部
End
如果觉得我的文章对你有用,请随意赞赏