Community Forums › Forums › Design Tips and Tricks › Post Views In Byline
This topic contains 5 replies, has 3 voices, and was last updated by dev454 3 months, 2 weeks ago.
-
AuthorPosts
-
February 2, 2013 at 1:16 am #17315
Does anyone have a good solution for putting the post views in the byline?
February 2, 2013 at 8:34 pm #17513Have you tried the WP-Post Views plugin?
http://wordpress.org/extend/plugins/wp-postviews/
Susan @ Graphically Designing I’d love to customize your website! I tweet!
I’ve taken up the challenge! – help me answer some of the unanswered postsFebruary 2, 2013 at 8:38 pm #17514I looked at it, but how would I get it in the byline via the functions.php without modifying core code?
February 2, 2013 at 10:00 pm #17533Is this what you are looking for?
I got code from 2 different places, marked in a comment above each section:
/** Post Views */ /** -- <a href="http://www.wpbeginner.com/wp-tutorials/how-to-track-popular-posts-by-views-in-wordpress-without-a-plugin/" rel="nofollow">http://www.wpbeginner.com/wp-tutorials/how-to-track-popular-posts-by-views-in-wordpress-without-a-plugin/</a> -- */ 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); } } //To keep the count accurate, lets get rid of prefetching remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); function wpb_track_post_views ($post_id) { if ( !is_single() ) return; if ( empty ( $post_id) ) { global $post; $post_id = $post->ID; } wpb_set_post_views($post_id); } add_action( 'wp_head', 'wpb_track_post_views'); 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 View"; } return $count.' Views'; } /** Customize the post info function */ /** -- <a href="http://my.studiopress.com/snippets/post-info/" rel="nofollow">http://my.studiopress.com/snippets/post-info/</a> -- */ add_filter( 'genesis_post_info', 'post_info_filter' ); function post_info_filter($post_info) { if ( !is_page() ) { $post_info = '[post_date] by [post_author_posts_link] [post_comments] ' . wpb_get_post_views(get_the_ID()) . ' [post_edit] '; return $post_info; }}Sorry for formatting.
February 2, 2013 at 11:08 pm #17554dev454 – This is exactly what I’m looking for. The only problem is it’s counting 2 page views for each 1 visit.
February 2, 2013 at 11:50 pm #17559I’m using that code on a new test install (no plugins), and the metro child theme. I am only getting 1 page view per visit.
Maybe a caching plugin or some other plugin is calling the page or code twice for some reason.
-
AuthorPosts
You must be logged in to reply to this topic.