Loper主题页面添加百度收录提示,最近发现很多网站页面都添加了百度收录查询提示,为了方便查看自己文章是否给百度收录了,拽立网,所以我也要把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>

 

文章页面添加后的效果图!

Loper主题页面添加百度收录提示-拽立网

提示:添加后刷新自己的网站看看效果,如果位子不对了自己在调整!

提示:还要改(archive.php),(category.php),(tag.php),(search.php)!

Loper主题页面添加百度收录提示
版权声明:本站原创文章,于2015年11月25日,由 拽立网 发表,共 1638 字。
打赏