本页目录
来源于:
https://www.wpdaxue.com/WordPress-postviews-code.html
如下:
1.在主题的 functions.php 文件的最后一个 ?> 前面添加下面的代码:
/* 访问计数 */function record_visitors(){ if (is_singular()) { global $post; $post_ID = $post->ID; if($post_ID) { $post_views = (int)get_post_meta($post_ID, 'views', true); if(!update_post_meta($post_ID, 'views', ($post_views+1))) { add_post_meta($post_ID, 'views', 1, true); } } }}add_action('wp_head', 'record_visitors');
/// 函数名称:post_views/// 函数作用:取得文章的阅读次数function post_views($before = '(点击 ', $after = ' 次)', $echo = 1){global $post;$post_ID = $post->ID;$views = (int)get_post_meta($post_ID, 'views', true);if ($echo) echo $before, number_format($views), $after;else return $views;}2.在需要显示该统计次数的地方使用下面的代码调用:
<?php阅读: post_views(' ', ' 次'); ?>参考:
http://www.zixuephp.com/wzht/WordPress/20141128_8004.html