- WordPress 统计文章浏览数代码
- # vim functions.php ( SHIFT -g 在最后加入)
- /* added by ko */
- function getPostViews($postID){
- $count_key = ‘post_views_count’;
- $count = get_post_meta($postID, $count_key, true);
- if($count==”){
- delete_post_meta($postID, $count_key);
- add_post_meta($postID, $count_key, ’0′);
- return “0 View”;
- }
- return ‘浏览:’.$count;
- }
- function setPostViews($postID) {
- $count_key = ‘post_views_count’;
- $count = get_post_meta($postID, $count_key, true);
- if($count==”){
- $count = 0;
- delete_post_meta($postID, $count_key);
- add_post_meta($postID, $count_key, ’0′);
- }else{
- $count++;
- update_post_meta($postID, $count_key, $count);
- }
- } ?>
- 提示:为了方便可以将代码直接复制到编辑器如 mousepad 保存到文件 article-stat.php,接着:
- # cat article-stat.php >> function.php
- # vim single.php (在 the_content 上方加入代码:)
-
欢迎转载,请保留本文链接:” title=””>
-
- :wq