折腾备忘录

鉴于大发大神更新主题太快,我每次升级主题都要修改一部分代码,所以记下来,以免以后忘记改了些啥

pgy

1 .百度推送functions.php

//百度链接自动提交

function fa_push_to_baidu($post_ID){

global $post;

if( $post->post_status != “publish” ){

$urls = array(

get_permalink($post_ID),

);

$api = ‘http://data.zz.baidu.com/urls?site=blog.aotxland.com&token=p1HGiW646KZ4zhVa&type=original’;//替换成你的接口调用地址

$ch = curl_init();

$options =  array(

CURLOPT_URL => $api,

CURLOPT_POST => true,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_POSTFIELDS => implode(“n”, $urls),

CURLOPT_HTTPHEADER => array(‘Content-Type: text/plain’),

);

curl_setopt_array($ch, $options);

$result = curl_exec($ch);

//var_dump($result);

}

}

add_action(‘publish_post’, ‘fa_push_to_baidu’);

2.网站统计footor.php

<!–统计–>

<script>

var _hmt = _hmt || [];

(function() {

var hm = document.createElement(“script”);

hm.src = “//hm.baidu.com/hm.js?cea220f963e3f32796ab07cf34c87148”;

var s = document.getElementsByTagName(“script”)[0];

s.parentNode.insertBefore(hm, s);

})();

</script>

3.版权 footor.php

<a href=”http://www.aotxland.com” target=”_blank”>AoTxLand</a> © 2016 京ICP备15042352号 </p><p>

theme by <a href=”https://fatesinger.com” target=”_blank”>bigfa</a>

4.网站描述.header.php

<?php

//如果是首页

if (is_home()){

$keywords = “Yif,韩小哈,翱天翔地,中型组机器人,折腾”;

$description = “翱天翔地:记录行走和折腾之路”;}

//如果是文章页

elseif (is_single()){

//默认使用文章页添加关键字

$keywords = get_post_meta($post->ID, “keywords”, true);

//如果为空,使用标签作为关键字

if($keywords == “”){

$tags = wp_get_post_tags($post->ID);                foreach ($tags as $tag){

$keywords = $keywords.$tag->name.”,”;                }

//去掉最后一个,

$keywords = rtrim($keywords, ‘, ‘);        }

//默认使用文章页添加描述

$description = get_post_meta($post->ID, “description”, true);

//如果为空,使用文章前100个字作为描述

if($description == “”){                if($post->post_excerpt){

$description = $post->post_excerpt;                }else{

$description = mb_strimwidth(strip_tags(apply_filters(‘the_content’,$post->post_content)),0,200);                }        }}

//如果是页面,使用页面添加的关键字和描述

elseif (is_page()){

$keywords = get_post_meta($post->ID, “keywords”, true);

$description = get_post_meta($post->ID, “description”, true);}

//如果是分类页,使用分类名作为关键字,分类描述作为描述

elseif (is_category()){

$keywords = single_cat_title(“, false);

$description = category_description();}

//如果是标签页,使用标签名作为关键字,标签描述作为描述

elseif (is_tag()){

$keywords = single_tag_title(“, false);

$description = tag_description();}

//去掉两段空格

$keywords = trim(strip_tags($keywords));

$description = trim(strip_tags($description));?>

<meta name=”keywords” content=”<?php echo $keywords; ?>” />

<meta name=”description” content=”<?php echo $description; ?>” />

</h1>

<?php $description = get_bloginfo( ‘description’, ‘display’ );

if ( $description ) : ?>

<p class=”site-description”><?php echo $description; ?></p>

共有 3 条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注