wordpress代码检测当前页面百度是否收录

作为 wordpress 站长,一定遇到过发布了许多文章而百度没有收录的情况,或者已经收录了,还需要你去单独查看该文章是否被百度收录,很是麻烦,对于新上线网站总会去查询网页收录了多少,哪些还没收录。这个功能实用性极佳。

方法一

下面只需一段代码即可随时了解百度收录情况,并提供提交百度入口,以加速百度收录。

//百度收录提示
if(git_get_option('git_baidurecord_b') && function_exists('curl_init')):
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 title="" href="https://www.baidu.com/s?wd=' . get_the_title() . '" target="_blank"
rel="external nofollow" data-original-title="点击查看">已收录</a>';
} else {
echo '<a style="color: red;" title="" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename=' . get_permalink() . '" target="_blank"
rel="external nofollow" data-original-title="点击提交,谢谢您!">未收录</a>';
}
}
endif;

上面的函数式放在主题 functions 文件中,然后在文章内容页面适合地方加入下方这段代码

<?php if (git_get_option('git_baidurecord_b') && function_exists('curl_init')) { ?><span class="muted"><i class="fa fa-flag"></i> <?php
baidu_record(); ?></span>

方法二

只有管理员才能在站台看到该文章是否被百度收录的提示,其它的访客是完全看不到的,而且本代码有自动的未收录提示功能,如果我们点击未收录提示字样,可以直接链接到提交百度站长链接的页面,主动向百度提交我们未被收录的文章链接,而且操作成本也很低,只需要把以下的代码复制到我们当前的 wordpress 主题文件夹的 functions.php 文章中,即可实现:

/* 检查百度是否已收录文章页面 管理员可以见 */
function d4v($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;
}
}
add_filter( 'the_content', 'baidu_submit' );
function baidu_submit( $content ) {
if( is_single() && current_user_can( 'manage_options') )
if(d4v(get_permalink()) == 1)
echo '<p align=right><b><a target="_blank" title="点击查看" rel="external nofollow" href="https://www.baidu.com/s?wd='.get_the_title().'">此文章已被百度收录</a></b>(仅管理员可见)</p>';
else
$content="<p align=right><b><a style=color:red target=_blank href=https://zhanzhang.baidu.com/sitesubmit/index?sitename=".get_permalink().">百度未收录!点击此处一键提给百度交</a></b>(仅管理员可见)</p>".$content;
return $content;
}
/* 检查百度是否已收录文章页面 管理员可以见 */

 

http://xzh.i3geek.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请不要用于商业用途及非法用途,否则后果自负!
3. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"qq301.com",如遇到无法解压的请联系管理员!
资源客是一个优秀的分享资源站,本站资源均为各位友友分享而来,特殊原创会标明如有侵犯版权等可联系删除

资源客 » wordpress代码检测当前页面百度是否收录