本教程是为了解决那些刚刚创建的网站,被访客浏览时,网站文章阅读量数字显示个位或是十位数的尴尬,以下内容只针对于主题安装或是集成了wp-postviews插件的wordpress主题,通过以下wordpress插件的修改方法与wordpress主题的修改方法实现流量爆棚的效果。
插件修改/wp-content/plugins/wp-postviews/wp-postviews.php文件646行函数increment_views:
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 29 30 |
### Function: Increment Post Views increment_views(); function increment_views() { global $wpdb; $post_id = intval($_GET['postviews_id']); if($post_id > 0 && defined('WP_CACHE') && WP_CACHE) { $post_views = get_post_custom($post_id); $post_views = intval($post_views['views'][0]); if(!update_post_meta($post_id, 'views', ($post_views+1))) { add_post_meta($post_id, 'views', 1, true); } } } 修改后: ### Function: Increment Post Views increment_views(); function increment_views() { global $wpdb; $post_id = intval($_GET['postviews_id']); if($post_id > 0 && defined('WP_CACHE') && WP_CACHE) { $post_views = get_post_custom($post_id); $post_views = intval($post_views['views'][0]); $viewrnd=rand(2,5); if(!update_post_meta($post_id, 'views', ($post_views+$viewrnd))) { add_post_meta($post_id, 'views', $viewrnd, true); } } } |