• Resolved webguync

    (@webguync)


    I have seen some blogs which display the number of views beside the date posted on and posted by tagline. so it would say this post has been viewed 2000 times or something like that. Does anyone know how this is done?

    TIA

Viewing 15 replies - 1 through 15 (of 17 total)
  • Usually via a post views plugin.

    Thread Starter webguync

    (@webguync)

    so, I downloaded the post-views plugin and the read-me file says to place the following code after <php if ( have_post() ) while ( have_post() ) : the_post();?>

    echo_post_views(get_the_ID());

    I did that, but don’t see any thing on my blog. I wanted it to show up next to the blog author picture id, and posted ondate: by:author_name

    any ideas?

    You have to place the code in the relevant theme template file – e.g. single.php.

    Thread Starter webguync

    (@webguync)

    I did, maybe I have it in the wrong lace. Here is where it currently lies.

    <div id="content" role="main">
    
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
    				<div id="nav-above" class="navigation">
    					<div class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'twentyten' ) . '</span> %title' ); ?></div>
    					<div class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'twentyten' ) . '</span>' ); ?></div>
    				</div><!-- #nav-above -->
    
    				<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    					<h1 class="entry-title"><?php the_title(); ?></h1>
      <div id="Blog_Views">
                                echo_post_views(get_the_ID());
                                </div>

    Try using <?php echo_post_views(get_the_ID());?>

    Thread Starter webguync

    (@webguync)

    thanks, I tried that, but still not displaying. Maybe I am putting the code in the wrong place?

    Thread Starter webguync

    (@webguync)

    just an update to this. I noticed that when you try to make a commment on a blog post, the following error is displayed.

    Fatal error: Call to undefined function echo_post_views() in /nfs/c08/h01/mnt/118256/domains/inspired-evolution.com/html/blog/wp-content/themes/Inspired-Evolution/single.php on line 17

    where would I need to define the function at? Also, I think single.php must be the wrong file to post this code in b/c I only want the page views to display below the blog post title.

    Try re-uploading a fresh copy of the theme using FTP or whatever file management application your host provides.

    Thread Starter webguync

    (@webguync)

    couldn’t I just take out the offending code?

    Do you know what that function is for?

    Thread Starter webguync

    (@webguync)

    yes, it’s supposed to display the blog views.

    If you don’t want it, then try removing the call to that function. But I suggest you make a backup copy of the file before making any changes.

    @webguync
    Just installed that plugin here also, I have add the suggestion Esmi made in single.php in a div
    <div>Total views <?php echo_post_views(get_the_ID());?> </div>
    Give the div some id or class if needed. I placed it just before <div class="rss"> and it works like a charm here.
    I hope it helps you a little.

    Note: maybe it needs also same line in page.php if you want it also overthere.

    Update:
    As soon I deactivate the plugin I also get same error as you have!
    After activating it again the error is gone..so (imho) the plugin is not flawless..but works.
    Seems error because it is not compatible with WP 3.2.1?

    As soon I deactivate the plugin I also get same error as you have!
    After activating it again the error is gone..so (imho) the plugin is not flawless..but works.

    It’s working exactly as it should. If the plugin is not activated, the code is not run and thus the function is not defined.

    @webguync

    The function is defined by the plugin. Check again to see if it’s activated.

    Thread Starter webguync

    (@webguync)

    ok, I activated the plugin and I see where it works when I go into a post to comment. I was hoping to have it display on the initial viewing of your blog where all of the post are where the author information is below the post title. I tried the code in page.php as below, but don’t see where it is working.

    <?php if ( is_front_page() ) { ?>
    <h2 class=”entry-title”><?php the_title(); ?></h2>
    <div>Total views <?php echo_post_views(get_the_ID());?> </div>

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘adding number of views to blog post’ is closed to new replies.