wp-content\themes\里面找到并打开你的主题目录。
将下面代码复制到functions.php的最下方,然后刷新页面就可以看到效果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 读取浏览次数
function xssl_post_clicks($uid) {
return 1+(int) get_post_meta($uid, 'post-clicks', TRUE);
}

function xssl_copyright($content) {
if(is_single() or is_feed()) {
global $post;
$content.='<div class="post-copyright">';
$content.='<div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="'.get_bloginfo('url').'">'.get_bloginfo('author').' </a></span></div>';
$content.='<div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="'.get_permalink().'">'.get_permalink().'</a></span></div>';
$content.='<div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外,均采用<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="'.get_bloginfo('url').'" target="_blank">'.get_bloginfo('name').'</a>!</span></div>';
$content.='<div class="post-copyright__author"><span class="post-copyright-meta">浏览次数: </span><span class="post-copyright-info"><a>' .xssl_post_clicks($post->ID).'</a></span></div>';
$content.='</div>';
}
return $content;
}
add_filter ('the_content', 'xssl_copyright');
// 刷新浏览次数
function update_xssl_post_clicks () {
if(is_singular()) {
global $post;
$views = (int) get_post_meta($post->ID, 'post-clicks', TRUE);
update_post_meta($post->ID, 'post-clicks', $views+1);
}
}
add_action( 'wp_footer', 'update_xssl_post_clicks' );

1