Created
May 5, 2014 17:51
-
-
Save DWboutin/2707be5fb63cfb1ffb80 to your computer and use it in GitHub Desktop.
Wordpress post view count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Compter le nombre de view | |
// Utiliser wpb_set_post_views($postID) dans toutes les pages à compter les views (single.php) | |
function wpb_set_post_views($postID) { | |
$count_key = 'wpb_post_views_count'; | |
$count = get_post_meta($postID, $count_key, true); | |
if($count==''){ | |
$count = 0; | |
delete_post_meta($postID, $count_key); | |
add_post_meta($postID, $count_key, '0'); | |
}else{ | |
$count++; | |
update_post_meta($postID, $count_key, $count); | |
} | |
} | |
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); | |
// obtenir le nombre de view | |
function wpb_get_post_views($postID){ | |
$count_key = 'wpb_post_views_count'; | |
$count = get_post_meta($postID, $count_key, true); | |
if($count==''){ | |
delete_post_meta($postID, $count_key); | |
add_post_meta($postID, $count_key, '0'); | |
return '0'; | |
} | |
return $count; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment