[Plugin: WP-PostViews] Added a function to get post views by post ID
-
Hello
I added a function in the plugin to get post views by post ID (get_the_views).
I also modified ‘the_views’ function to handle this new function.Hope this helps !
### Function: Display The Post Views function the_views($display = true, $prefix = '', $postfix = '', $always = false) { $views = get_the_views(null, $prefix, $postfix, $always); if ($display) { echo $views; } else { return $views; } } ### Function: Display The Post Views By Post ID if (!function_exists('get_the_views')) { function get_the_views($post_id = null, $prefix = '', $postfix = '', $always = false) { $post_id = (null === $post_id) ? get_the_ID() : $post_id; $custom_fields = get_post_custom_values('views', $post_id); $post_views = intval($custom_fields[0]); $views_options = get_option('views_options'); if ($always || should_views_be_displayed($views_options)) { $output = $prefix . str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']) . $postfix; return apply_filters('the_views', $output); } return ''; } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘[Plugin: WP-PostViews] Added a function to get post views by post ID’ is closed to new replies.