我们希望自己的博客文章看到具体的用户阅读和浏览数量,这里默认是没有的,我们可以加上代码或者插件实现的。
1、阅读数
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 |
//文章阅读统计 function post_views_record() { 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', 'post_views_record'); //获取阅读统计 function get_post_views() { global $post; $post_ID = $post->ID; $views = (int)get_post_meta($post_ID, 'views', true); return $views; } |
后台已经有的,但是我们也可以在前台调用。
1 |
get_post_views() |
后台展示数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
//后台日志阅读统计 add_filter('manage_posts_columns', 'postviews_admin_add_column'); function postviews_admin_add_column($columns) { $columns['views'] = __('阅读'); return $columns; } add_action('manage_posts_custom_column', 'postviews_admin_show', 10, 2); function postviews_admin_show($column_name, $id) { if ($column_name != 'views') { return; } $post_views = get_post_meta($id, "views", true); echo $post_views; } |
声明:本站发布的所有资源均来自于互联网,所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
如侵犯到您的权益,请及时通知我们,我们会及时处理。邮箱:505289534@qq.com
评论(0)