Modification of Top 10 Posts plugin
As is evident from looking at the sidebar to the right of this text, I am using the 'Top 10 posts and Views per post' WP plugin by Mark Ghosh. I am very happy with the "viewer popularity" rating this plugin provides, but I have been a little annoyed with my own page views being included in the view counts. Due to Adsense concerns, I have disabled the post preview in the WP post editor. This means that I tend go back and forth between viewing and editing a post - something which would capsize the view count.
I therefore decided to take a look at the plugin code, to see if it could somehow be modified to exclude requests made from the IP-addresses, I use.
The solution I came up with is shown in the code fragment below - I have added an IP check in lines 56 - 60 in
.
$me = FALSE;
$me = ($ip == '<INSERT FIRST IP HERE>' || $ip == '<INSERT OTHER IP HERE>');
global $id, $wpdb, $single;
if ($single && isset($id) && $id > 0 && !$me) {…
Now, I have no experience with PHP so I am not sure if this hack is 'come il faut' PHP, but it works :)
In the code shown above, I only exclude two IP adresses: The one at home and the one at work. It is entirely possible to exclude more, but I mostly access the blog from either one of those addresses, so excluding them removes the worst "error weigh in" in the view count.
If you enjoyed this post, make sure you subscribe to my RSS feed!
June 25th, 2007 at 22:32
Apparently the plugin’s been updated since you added that code(?) Cause on line 56-60 there’s just comments the way I see it.
Was it the
code you wrapped it around?
June 25th, 2007 at 22:53
No, I modified the function
by adding the code snippet (in the above post) at line 56 in the file ‘top10.php’.
If I look at the ‘Top 10 posts and Views per post’ WP plugin, I link to in the post above, that plugin has not been updated with the IP check I have added.
Maybe you have come across a different version? Do you have a link to the version you are referring to?
June 26th, 2007 at 00:55
Ah yeah it all makes sense now :) It was that exact file I had but for some reasons either Dreamweaver or Wordpress added an empty line on every other line in the comments section in the head of the file.
Thanks.