A Silly Mistake not to make, when Using Post-Views Counter

During my previous posting, I did write that I not only use WordPress, but that I actually use a plug-in named ‘‘. In fact this plug-in will work correctly by itself, and only requires that the blogger add special code to the PHP () scripts of WordPress, if he or she wants special behavior from the plug-in.

Not realizing this, I had put the following lines of code at the bottom of the file ‘‘:

 


<?php
/**
 * Loads the WordPress environment and template.
 *
 * @package WordPress
 */

if ( !isset($wp_did_header) ) {

        $wp_did_header = true;

        require_once( dirname(__FILE__) . '/wp-load.php' );

        wp();

        require_once( ABSPATH . WPINC . '/template-loader.php' );

        echo do_shortcode( '' );
//        pvc_view_post( $wp_query->post->ID );
}


 

Since then, I have commented out that last, offending line. The effect which that line had produced, in my logged-in view, was this:

post-views_3

The first posting of my blog home page was never really viewed, 37 times by itself, as the widget would indicate. But there does exist a home page of my blog, which displays the 4 most-recent postings, and views of which I do not want counted. The problem here is the fact that this expression:

 


( $wp_query->post->ID )

 

Returns a valid Post-ID, when there are 4 postings on the same page. I had not expected this. But this expression returns the Post-ID of the topmost posting in the home page.

What this means is that an unexpected number of readers actually visit my blog, not because they have been led to one specific posting, but because they are just curious about what I have been up to. 37 readers did so recently.

But all that traffic got associated with that most-recent posting, at the top of the home-page.

So, unless WordPress users want their visitors counted in this way, I suggest not to put that line of code.

Dirk

 

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *

Please Prove You Are Not A Robot *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>