WordPress.org

Ready to get started?Download WordPress

Forums

post-views
Show views in post (9 posts)

  1. hornets2002
    Member
    Posted 1 year ago #

    Great plugin, I was wondering if it was possible to echo the total views for each post in single.php. I know this is possible with other plugins but this is the only plugin that shows views based on unique visitors. So I would really like to get this function working. Any help would be greatly appreciated.

    Thanks in advance!

    http://wordpress.org/extend/plugins/post-views/

  2. faeronsayn
    Member
    Posted 1 year ago #

    I really need to know how to do this as well.

  3. hornets2002
    Member
    Posted 1 year ago #

    Hey faeronsayn,

    I never got a response from the developer of this plugin, so I took it upon myself to figure this out. I played around in PHP and came up with a working solution :)

    <span class="single-post-views"><?php echo get_post_views('normal'); ?><?php _e(' reads', 'gonzo'); ?></span>

    It should display something like this: "233 reads". If you want to change the wording, just alter the writing in the parenthesis to whatever you'd like.

    Also where it says 'gonzo', I'm not sure but you might need to change it to your theme name.

    Hope this helps!

  4. hornets2002
    Member
    Posted 1 year ago #

    Oh yeah forgot, paste the above code in single.php in your theme folder.

  5. faeronsayn
    Member
    Posted 1 year ago #

    hornets, could this be used for custom post types as well?

  6. hornets2002
    Member
    Posted 1 year ago #

    Yes, the code will work anywhere you want it to as long as it is placed in the correct file that corresponds to the desired location

  7. faeronsayn
    Member
    Posted 1 year ago #

    Alright, thanks again :)

  8. oomskaap
    Member
    Posted 1 year ago #

    I think a better way is maybe

    <?php if(function_exists('get_post_views')) { echo get_post_total_views(); _e(' views'); } ?>

  9. hornets2002
    Member
    Posted 1 year ago #

    Thanks for offering an alternative oomskaap. I'm not very knowledgeable in php, would you mind explaining why it's better? Would it increase speed on my site? Just curious cuz ill use your method if so :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags