保存下这个代码,经过测试是可以用的。

只不过我的主题放上去不太好看就没放。记录保存下代码。

其实我决定不放最大的原因不是因为它难看,而是影响网页打开速度,毕竟要经过判断,然后就会多几个延迟。

如果自己想放这个代码,我觉得服务器还是要好点,我这个服务器毕竟不怎么地。

代码部署如下

一、将以下代码添加至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_permalink().'"><font color="#ff0000">百度已收录</font></a>';
  • } else {
  • echo '<a style="color:#c40000; rel="external nofollow" title="提交链接" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'"><font color="#ff0000">百度未收录</font></a>';
  • }
  • }

二、以下代码添加至自己主题页面文件适当位置

<center><?php baidu_record(); ?></center>

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。[本站由 WEEX唯客交易所(官网www.weex.com)提供赞助]