Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- About Time POST Count
- --- functions.php
- // Display or Count how many times a post has been viewed.
- // id = the post id and action = display or count
- function arixWp_PostViews( $id, $action ) {
- $axCountMeta = 'ax_post_views';
- // Your Custom field that stores the views
- $axCount = get_post_meta($id, $axCountMeta, true);
- if ( $axCount == '' ) {
- if ( $action == 'count' ) {
- $axCount = 0; }
- delete_post_meta( $id, $axCountMeta );
- add_post_meta( $id, $axCountMeta, 0 );
- if ( $action == 'display' ) { echo '<span class="times-read">Be The First To Read And Share!!</span>'; } }
- else { if ( $action == 'count' ) {
- $axCount++; update_post_meta( $id, $axCountMeta, $axCount );
- }
- else { echo '<span class="times-read">Has Been Read ' . $axCount . ' Times!</span>';
- }
- } }
- //allbloggingtips.com/2011/12/19/add-post-views-counter-in-wordpress-posts-without-plugin/#ixzz2XLmIwM00
- --- single/pages files :
- Add this as a class (Not in loop) (Gives the ID to read)
- <?php the_ID(); ?>
- Add this after "the_post();" (It counts the IDs)
- echo arixWp_PostViews( get_the_ID(), 'count' );
- Add this out of the loop. . . (It shows the post count)
- echo arixWp_PostViews( get_the_ID(), 'display' );
- --- category and other loops
- Add this to display the count after "the_post();"
- echo arixWp_PostViews( $post->ID, 'display' );
- That should be it. . . Test and retest
Advertisement
Add Comment
Please, Sign In to add comment