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

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