Loper主题页面添加百度收录提示,最近发现很多网站页面都添加了百度收录查询提示,为了方便查看自己文章是否给百度收录了,拽立网,所以我也要把Loper主题添加百度收录这个功能,本人是使用免插件的百度收录提示功能,今天我把Loper主题页面添加百度收录提示方法分享给大家,请看以下操作!
首页页面添加后效果图!
1.登陆你的后台管理,选择【外观】-【编辑】-【模板函数 (functions.php)】
直接添加下面全部代码:【?>前面】
//百度收录查询
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().'">已收录</a>';
} else {
echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'">未收录</a>'; }}
2.登陆你的后台管理,选择【外观】-【编辑】-【loper: 首页模板 (index.php)】
直接搜索这个代码:
<span class="cate left"><?php the_time('Y.m.j'); ?>
找到这个代码直接在它下面添加以下代码:
<span class="singlerelate"><?php baidu_record(); ?></span>
3.登陆你的后台管理,选择【外观】-【编辑】-【loper: 文章页面 (single.php)】
直接搜索这个代码:
<span class="singletime"><?php the_time('Y.m.j'); ?></span>
找到这个代码直接在它下面添加以下代码:
<span class="singlerelate"><?php baidu_record(); ?></span>
文章页面添加后的效果图!
提示:添加后刷新自己的网站看看效果,如果位子不对了自己在调整!
提示:还要改(archive.php),(category.php),(tag.php),(search.php)!

版权声明:本站原创文章,于2015年11月25日,由 拽立网 发表,共 1638 字。
打赏



原来是这样啊.,我说我之前的百度一直收录不是很好呢,感谢博主!
这个是百度查看收录功能而已,有空再来聊天!
管理员回复这个不好用了,添加后网站打不开了
打不开,可能是你没弄好!不可能我的代码有问题啊!

管理员回复@拽立: 我也不知道为什么啊,记得第一次是弄好了的,结果后面不知道出了什么问题,然后主图乱了。我就从头再来,以后就再也没弄上了,不过对于现在这样已经很满意了O(∩_∩)O哈哈~
@╄→寒冷的冰:
不可能这么麻烦啊,我记得这样写的教程没错啊!除非你安装了什么插件又冲突! 
管理员回复@拽立: 恩可能是吧,还有我发现我回复你的评论的时候点击回复后不显示评论框,得点一下换个马甲才会显示评论框