From 84233c4d8b73f3b720463245f32d1e708e879c12 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sat, 25 Jan 2014 16:09:55 +1100 Subject: [PATCH] Count views for single posts and pages --- admin/hooks/manage-posts-columns.php | 1 + admin/hooks/the-content.php | 3 +- assets/js/sportspress.js | 18 ++++++++++-- functions.php | 44 +++++++++++++++------------- readme.txt | 9 ++++++ 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/admin/hooks/manage-posts-columns.php b/admin/hooks/manage-posts-columns.php index 73e99158..2e2570f1 100644 --- a/admin/hooks/manage-posts-columns.php +++ b/admin/hooks/manage-posts-columns.php @@ -4,6 +4,7 @@ function sportspress_manage_posts_columns( $defaults ){ return $defaults; } add_filter( 'manage_posts_columns', 'sportspress_manage_posts_columns' ); +add_filter( 'manage_page_posts_columns', 'sportspress_manage_posts_columns' ); function sportspress_manage_posts_custom_column( $column, $post_id ) { global $post; diff --git a/admin/hooks/the-content.php b/admin/hooks/the-content.php index 47c294d7..d09d98be 100644 --- a/admin/hooks/the-content.php +++ b/admin/hooks/the-content.php @@ -1,6 +1,7 @@ 640) { $(".sp-league-table, .sp-event-statistics, .sp-player-list").dataTable({ "aaSorting": [], @@ -45,7 +46,16 @@ function viewport() { }); } - // Responsive tables + + /* + * Responsive Tables + * + * Based on responsive-tables.js by ZURB + * + * Credit: ZURB + * Original: https://github.com/zurb/responsive-tables + */ + var switched = false; var updateTables = function() { if ((viewport().width <= 640) && !switched ){ @@ -111,7 +121,9 @@ function viewport() { }); } - // Google Maps + + /* Google Maps */ + function initialize_google_maps() { $maps = $('.sp-google-map'); $maps.each(function() { diff --git a/functions.php b/functions.php index 8c0b8812..b4d0b0db 100644 --- a/functions.php +++ b/functions.php @@ -107,28 +107,32 @@ if ( !function_exists( 'sportspress_get_the_term_id' ) ) { } } -function sportspress_get_post_views( $post_id ) { - $count_key = 'sp_views'; - $count = get_post_meta( $post_id, $count_key, true ); - if ( $count == '' ): - delete_post_meta( $post_id, $count_key ); - add_post_meta( $post_id, $count_key, '0' ); - return sprintf( _n( '1 View', '%1$s Views', '0', 'sportspress' ), '0' ); - endif; - return sprintf( _n( '1 View', '%1$s Views', $count, 'sportspress' ), $count ); +if ( !function_exists( 'sportspress_get_post_views' ) ) { + function sportspress_get_post_views( $post_id ) { + $count_key = 'sp_views'; + $count = get_post_meta( $post_id, $count_key, true ); + if ( $count == '' ): + delete_post_meta( $post_id, $count_key ); + add_post_meta( $post_id, $count_key, '0' ); + return sprintf( _n( '1 View', '%1$s Views', '0', 'sportspress' ), '0' ); + endif; + return sprintf( _n( '1 View', '%1$s Views', $count, 'sportspress' ), $count ); + } } -function sportspress_set_post_views( $post_id ) { - $count_key = 'sp_views'; - $count = get_post_meta( $post_id, $count_key, true ); - if ( $count == '' ): - $count = 0; - delete_post_meta( $post_id, $count_key ); - add_post_meta( $post_id, $count_key, '0' ); - else: - $count++; - update_post_meta( $post_id, $count_key, $count ); - endif; +if ( !function_exists( 'sportspress_set_post_views' ) ) { + function sportspress_set_post_views( $post_id ) { + $count_key = 'sp_views'; + $count = get_post_meta( $post_id, $count_key, true ); + if ( $count == '' ): + $count = 0; + delete_post_meta( $post_id, $count_key ); + add_post_meta( $post_id, $count_key, '0' ); + else: + $count++; + update_post_meta( $post_id, $count_key, $count ); + endif; + } } if ( !function_exists( 'sportspress_get_post_precision' ) ) { diff --git a/readme.txt b/readme.txt index 44d6968a..34705d4d 100644 --- a/readme.txt +++ b/readme.txt @@ -72,6 +72,15 @@ SportsPress is currently in beta and is undergoing testing. We are still activel == Changelog == += 0.2 = +* Feature - Add option to select whether statistics are calculated as a sum or average. +* Feature - Enable pageview tracking for posts and custom post types. +* Feature - Responsive datatables. +* Fix - Add site admin capabilities for multisite. +* Fix - Force numerical sorting of number column. +* Tweak - Enable SportsPress content functions to be called without explicit ID. +* Tweak - Remove redundant admin menu links via filter. + = 0.1.10 = * Documentation - Add Installation, FAQ and Screenshots to assets.