Permalink
Browse files

upgrading to ver 1.62 from http://plugins.svn.wordpress.org/wp-postvi…

…ews/trunk/ -- rev 631696
  • Loading branch information...
1 parent 6a0917c commit 29aab760c0bad6f27f46a3c1d4f2e97a17dc8f9a Matt Richmond committed Nov 29, 2012
Showing with 33 additions and 7 deletions.
  1. +4 −0 readme.txt
  2. +29 −7 wp-postviews.php
View
@@ -35,6 +35,10 @@ Enables you to display how many times a post/page had been viewed.
* I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appericiate it. If not feel free to use it without any obligations.
== Changelog ==
+= Version 1.62 (29-11-2012) =
+* Add "Views" Column To Manage Pages In WP-Admin
+* Add Sortable "Views" Column To Manage Posts/Pages In WP-Admin
+
= Version 1.61 (21-05-2012) =
* Move AJAX Request to wp-admin/admin-ajax.php
View
@@ -3,7 +3,7 @@
Plugin Name: WP-PostViews
Plugin URI: http://lesterchan.net/portfolio/programming/php/
Description: Enables you to display how many times a post/page had been viewed. Modified by <a href="http://DPotter.net/Technical/" title="David's Technical Musings">David Potter</a> to include options for when and where to display view counts.
-Version: 1.61
+Version: 1.62
Author: Lester 'GaMerZ' Chan
Author URI: http://lesterchan.net
*/
@@ -435,7 +435,7 @@ function get_totalviews($display = true) {
global $wpdb;
$total_views = intval($wpdb->get_var("SELECT SUM(meta_value+0) FROM $wpdb->postmeta WHERE meta_key = 'views'"));
if($display) {
- echo $total_views;
+ echo number_format_i18n($total_views);
} else {
return $total_views;
}
@@ -651,22 +651,44 @@ function increment_views() {
}
### Function Show Post Views Column in WP-Admin
-add_action('manage_posts_custom_column', 'add_postviews_column_content', 5, 2);
-add_filter('manage_posts_columns', 'add_postviews_column', 5, 2);
-function add_postviews_column( $defaults ) {
- $defaults['viewscolumn'] = 'Views';
+add_action('manage_posts_custom_column', 'add_postviews_column_content');
+add_filter('manage_posts_columns', 'add_postviews_column');
+add_action('manage_pages_custom_column', 'add_postviews_column_content');
+add_filter('manage_pages_columns', 'add_postviews_column');
+function add_postviews_column($defaults) {
+ $defaults['views'] = 'Views';
return $defaults;
}
### Functions Fill In The Views Count
function add_postviews_column_content($column_name) {
- if( $column_name == 'viewscolumn' ) {
+ if($column_name == 'views') {
if(function_exists('the_views')) { the_views(); }
}
}
+### Function Sort Columns
+add_filter('manage_edit-post_sortable_columns', 'sort_postviews_column');
+add_filter('manage_edit-page_sortable_columns', 'sort_postviews_column');
+function sort_postviews_column($defaults)
+{
+ $defaults['views'] = 'views';
+ return $defaults;
+}
+add_action('pre_get_posts', 'sort_postviews');
+function sort_postviews($query) {
+ if(!is_admin())
+ return;
+ $orderby = $query->get('orderby');
+ if('views' == $orderby) {
+ $query->set('meta_key', 'views');
+ $query->set('orderby', 'meta_value_num');
+ }
+}
+
+
### Class: WP-PostViews Widget
class WP_Widget_PostViews extends WP_Widget {
// Constructor

0 comments on commit 29aab76

Please sign in to comment.