Count views for single posts and pages
This commit is contained in:
@@ -4,6 +4,7 @@ function sportspress_manage_posts_columns( $defaults ){
|
|||||||
return $defaults;
|
return $defaults;
|
||||||
}
|
}
|
||||||
add_filter( 'manage_posts_columns', 'sportspress_manage_posts_columns' );
|
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 ) {
|
function sportspress_manage_posts_custom_column( $column, $post_id ) {
|
||||||
global $post;
|
global $post;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
function sportspress_the_content( $content ) {
|
function sportspress_the_content( $content ) {
|
||||||
|
if ( is_single() || is_page() )
|
||||||
sportspress_set_post_views( get_the_ID() );
|
sportspress_set_post_views( get_the_ID() );
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ function viewport() {
|
|||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
|
|
||||||
// Data tables
|
/* Data Tables */
|
||||||
|
|
||||||
if (viewport().width > 640) {
|
if (viewport().width > 640) {
|
||||||
$(".sp-league-table, .sp-event-statistics, .sp-player-list").dataTable({
|
$(".sp-league-table, .sp-event-statistics, .sp-player-list").dataTable({
|
||||||
"aaSorting": [],
|
"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 switched = false;
|
||||||
var updateTables = function() {
|
var updateTables = function() {
|
||||||
if ((viewport().width <= 640) && !switched ){
|
if ((viewport().width <= 640) && !switched ){
|
||||||
@@ -111,7 +121,9 @@ function viewport() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Google Maps
|
|
||||||
|
/* Google Maps */
|
||||||
|
|
||||||
function initialize_google_maps() {
|
function initialize_google_maps() {
|
||||||
$maps = $('.sp-google-map');
|
$maps = $('.sp-google-map');
|
||||||
$maps.each(function() {
|
$maps.each(function() {
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ if ( !function_exists( 'sportspress_get_the_term_id' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sportspress_get_post_views( $post_id ) {
|
if ( !function_exists( 'sportspress_get_post_views' ) ) {
|
||||||
|
function sportspress_get_post_views( $post_id ) {
|
||||||
$count_key = 'sp_views';
|
$count_key = 'sp_views';
|
||||||
$count = get_post_meta( $post_id, $count_key, true );
|
$count = get_post_meta( $post_id, $count_key, true );
|
||||||
if ( $count == '' ):
|
if ( $count == '' ):
|
||||||
@@ -116,9 +117,11 @@ function sportspress_get_post_views( $post_id ) {
|
|||||||
return sprintf( _n( '1 View', '%1$s Views', '0', 'sportspress' ), '0' );
|
return sprintf( _n( '1 View', '%1$s Views', '0', 'sportspress' ), '0' );
|
||||||
endif;
|
endif;
|
||||||
return sprintf( _n( '1 View', '%1$s Views', $count, 'sportspress' ), $count );
|
return sprintf( _n( '1 View', '%1$s Views', $count, 'sportspress' ), $count );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sportspress_set_post_views( $post_id ) {
|
if ( !function_exists( 'sportspress_set_post_views' ) ) {
|
||||||
|
function sportspress_set_post_views( $post_id ) {
|
||||||
$count_key = 'sp_views';
|
$count_key = 'sp_views';
|
||||||
$count = get_post_meta( $post_id, $count_key, true );
|
$count = get_post_meta( $post_id, $count_key, true );
|
||||||
if ( $count == '' ):
|
if ( $count == '' ):
|
||||||
@@ -129,6 +132,7 @@ function sportspress_set_post_views( $post_id ) {
|
|||||||
$count++;
|
$count++;
|
||||||
update_post_meta( $post_id, $count_key, $count );
|
update_post_meta( $post_id, $count_key, $count );
|
||||||
endif;
|
endif;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sportspress_get_post_precision' ) ) {
|
if ( !function_exists( 'sportspress_get_post_precision' ) ) {
|
||||||
|
|||||||
@@ -72,6 +72,15 @@ SportsPress is currently in beta and is undergoing testing. We are still activel
|
|||||||
|
|
||||||
== Changelog ==
|
== 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 =
|
= 0.1.10 =
|
||||||
* Documentation - Add Installation, FAQ and Screenshots to assets.
|
* Documentation - Add Installation, FAQ and Screenshots to assets.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user