Skip to content

Instantly share code, notes, and snippets.

@wichaksono
Created January 23, 2018 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wichaksono/e87d5aaf4db4fbd2b5e411c608bb5e54 to your computer and use it in GitHub Desktop.
Save wichaksono/e87d5aaf4db4fbd2b5e411c608bb5e54 to your computer and use it in GitHub Desktop.
/**
* sedikit Modifikasi :D
* @see http://www.edikomputer.com/2013/03/cara-membuat-pageview-di-setiap-artikel.html
* untuk menngetahui berapa kali sebuah artikel dibaca
*/
function the_post_count($post_id = '')
{
$postid = $post_id;
if ($post_id == '') {
global $post;
$postid = $post->ID;
}
$post_count = get_post_meta($postid, 'post_count_view', true);
/**
* jika berada di halaman single atau artikel full
* harus diberi get_the_ID()
*
* ex : <?php the_post_count(get_the_ID()); ?>
**/
if (is_single() && $post_id != '') {
if ($post_count == '') {
$post_count = 1;
} else {
$post_count++;
}
update_post_meta($postid, 'post_count_view', $post_count);
}
echo ($post_count != '') ? $post_count : 0;
}
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment