Post Views In Byline

Community Forums Forums Design Tips and Tricks Post Views In Byline

This topic is: not resolved

This topic contains 5 replies, has 3 voices, and was last updated by  Eric R. Stoeckel, Jr. 1 year, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #17315

    buddy_boy8403
    Participant

    Does anyone have a good solution for putting the post views in the byline?

    #17513

    Susan
    Moderator

    Have you tried the WP-Post Views plugin?

    http://wordpress.org/extend/plugins/wp-postviews/


    Susan @ Graphically Designing I offer theme customizations I tweet!
    I’ve taken up the challenge! – help me answer some of the unanswered posts

    #17514

    buddy_boy8403
    Participant

    I looked at it, but how would I get it in the byline via the functions.php without modifying core code?

    #17533

    Is this what you are looking for?

    I got code from 2 different places, marked in a comment above each section:

    
    /** Post Views */
    
    /** &#8212; <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> &#8212; */
     function wpb_set_post_views($postID) {
     $count_key = &#8216;wpb_post_views_count';
     $count = get_post_meta($postID, $count_key, true);
     if($count==&#8221;){
     $count = 0;
     delete_post_meta($postID, $count_key);
     add_post_meta($postID, $count_key, &#8216;0&#8217;);
     }else{
     $count++;
     update_post_meta($postID, $count_key, $count);
     }
     }
     //To keep the count accurate, lets get rid of prefetching
     remove_action( &#8216;wp_head&#8217;, &#8216;adjacent_posts_rel_link_wp_head&#8217;, 10, 0);
    
    function wpb_track_post_views ($post_id) {
     if ( !is_single() ) return;
     if ( empty ( $post_id) ) {
     global $post;
     $post_id = $post-&gt;ID;
     }
     wpb_set_post_views($post_id);
     }
     add_action( &#8216;wp_head&#8217;, &#8216;wpb_track_post_views&#8217;);
    
    function wpb_get_post_views($postID){
     $count_key = &#8216;wpb_post_views_count';
     $count = get_post_meta($postID, $count_key, true);
     if($count==&#8221;){
     delete_post_meta($postID, $count_key);
     add_post_meta($postID, $count_key, &#8216;0&#8217;);
     return &quot;0 View&quot;;
     }
     return $count.&#8217; Views';
     }
    
    /** Customize the post info function */
     /** &#8212; <a href="http://my.studiopress.com/snippets/post-info/" rel="nofollow">http://my.studiopress.com/snippets/post-info/</a> &#8212; */
     add_filter( &#8216;genesis_post_info&#8217;, &#8216;post_info_filter&#8217; );
     function post_info_filter($post_info) {
     if ( !is_page() ) {
     $post_info = &#8216;[post_date] by [post_author_posts_link] [post_comments] &#8216; . wpb_get_post_views(get_the_ID()) . &#8216; [post_edit] &#8216;;
     return $post_info;
     }}
    
    

     

    Sorry for formatting.


    Twitter: @estoeckel

    #17554

    buddy_boy8403
    Participant

    dev454 – This is exactly what I’m looking for.  The only problem is it’s counting 2 page views for each 1 visit.

    #17559

    I’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.


    Twitter: @estoeckel

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.