Count views for single posts and pages

This commit is contained in:
Brian Miyaji
2014-01-25 16:09:55 +11:00
parent 8db2a05fa3
commit 84233c4d8b
5 changed files with 51 additions and 24 deletions

View File

@@ -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;

View File

@@ -1,6 +1,7 @@
<?php
function sportspress_the_content( $content ) {
sportspress_set_post_views( get_the_ID() );
if ( is_single() || is_page() )
sportspress_set_post_views( get_the_ID() );
return $content;
}
add_filter( 'the_content', 'sportspress_the_content' );

View File

@@ -9,7 +9,8 @@ function viewport() {
(function($) {
// Data tables
/* Data Tables */
if (viewport().width > 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() {

View File

@@ -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' ) ) {

View File

@@ -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.