For quite some time now, Mark has had some PHP code snippets just hanging around here on the site. Feeling the need to create a plugin for it and cite the documentation a little better, I did so. You may now find the, once what was just code, plugin Top 10 Posts/Views.
This plugin functions as a means to showing your top 10 posts (sorted by number of views) and displaying the total number of views on a per post basis. I have seen many sites use this code and now it is a plugin for all to use.
Update on 04/08/05: I have updated this script with better documentation and easier use of the script. Please note the documentation in the script itself at the top and you may refer to this page I have created to show some examples of the code.
Ok, I’ve uploaded and activated the plugin, and am a little lost on what to do next. Any help is appreciated. Thanks. BTW, I noticed you linking to BrowseHappy.org, did you have anything to do with that site? I was one of the interviewees and my story is still there.
If you view the actual plugin, it has instructions in the file itself. I may re-upload the file with 2 files. So just download it again and view it to see how to use it.
It really a plugin what I want!!
I use the pool Theme,and i can’t find this code in my index.php
How to?
I can’t get it to work either. I’m using 1.5 and basically copied the default theme over to the theme directory that the install created, and used my stylesheet from 1.2
I’m guessing the line:
0) { add_count($p);}?> goes into single.php but nothing posts to the mostAccessed table. I’ve tried moving the line to about 4 or 5 different places and still nothing happened 🙁
hrmm… ok after fiddling for a little I found where it goes. In the default wp 1.5 template it would go right before the line that says:
the only problem now is with permalinks the url isn’t calling ?p=postnumber so the postnumber is passing as 0. the statement checks for that so nothing goes to the database =\
If i go to mydomain.com/?p=399
it works
If i go to mydomain.com/archives/2005/03/13/postname/
it doesnt work 🙁
Is there any way to fix that?
I got it 😛
replaced $p with $id and it worked
Hi
I also have some problems with this one, first I cannot find the line you are refering to, I added it inside the loop but it does not seem to add any data to the db. When running the webpage I get an error
Warning: Invalid argument supplied for
foreach() in …\plugins\top10.php on line 67
Thanks for any help.
Sorry about the mix-up then. I’ll make an update to it with corrections. It works fine under my other blogs, not sure why it’s not working here. Thanks for reporting it.
Jonathan: Thanks
kilikina: On what line did you put it?
oh lol… guess it got funked up by the php tags =\
it goes in single.php right on top of :
<?php endwhile; else: ?>
<p> <?php _e(‘Sorry, no posts matched your criteria.’); ?> </p>
I just got it working from this plugin, having used the hack for a while.
Couple of issues:
Compare what I have below with what is in the plugin and make the changes. This preserves code validity.
//$url = get_permalink($post->ID);
echo “<li><a href=”$siteurl”.”index.php?p=”.$post->ID.”&more=1&c=1″ title=”$text”
>$post_title</a> <strong>($result->cntaccess)</strong></li>”;
}
}
Hi, I now got it up & running, working great after the help from Podz.I do have a request. Could it be possible to write out the url rewrite urls instead of the p=x version somehow? It is just because of my stats, it will now as it is look like two different urls.
Is it possible?
Here is how it looks now http://jedisthlm.com/
And thanks again for a great plugin.
I will try to make the update today with those things. I’m not sure if I will be able to make it using the permalinks instead, but I’ll see what I can do.
to get the permanant links to work:
replace these lines:
//$url = get_permalink($post->ID);
echo “<li><a href=\”$siteurl”.”index.php?p=”.$post->ID.”&more=1&c=1\” title=\”$text\” />$post_title</a> <strong>($result->cntaccess)</strong></li><br/>”;
with:
$siteurl = get_permalink($post->ID);
echo “<li><a href=\”$siteurl\” title=\”$text\” />$post_title</a> <strong>($result->cntaccess)</strong></li><br/>”;
I’m actually still running into the problem of the foreach not working on line 67 for pop posts. Anyone find a fix for that? I tried to debug it, but couldn’t hack it yet. I’ll keep playing with it, but thoughts on it?
Bah, I’ve run out of time. I’m leaving the country for a little over a week and won’t have time to make the update quite yet. If anyone feels like they want to make all the changes needed and e-mail it to me, I will update the file on hand for people to download.
You can e-mail it to: yeahmmhmm@gmail.com — Hope everyone enjoys this plugin once it’s updated.
Are there any new updates on the directions to use this plugin?? Please let me know
Okay, I’m going to make an update to this script this weekend with the corrected code. Finally tweak it so it works just fine now. Give me a couple days and it will be updated for everyone to use 🙂
very nice!
i will use this for our malaysia camera blog – http://www.fotozzoom.com.my/wp/index.php
Is it possible to modify this to only show the top 10 posts of a given category?
No, sorry, that has not been coded nor is in the plan to do so. That would a lot more coding and plugin would be very extensive instead of the short and sweet plugin it is right now. But you are more than welcome to try to modify it yourself to try to get it to work.
is there a way to exclude an ip or a user from the top10 count?
so that the database doesn’t get updated for a certain ip or user?
There is nothing in the plans right now for that, it’s an as-is product and doesn’t have much or any development plans. You can try to code it in yourself though, if you wish. I simply ported it over to a plugin from which Laughing Lizard made, you may want to contact him about it.
Thanks, I used this on my site. It’s exactly what I as looking for.
I got around the problem of showing only a specific category by having a custom single.php for the category, and only having the plugin counter for that index. 🙂
I found a way to cut the queries down from 11 to 1, I e-mailed the author so he can update the code, and I posted a comment for it on my site: http://raybdbomb.com/05.31.200.....omment-964
Thank Jonathan to create this plug-in. It is useful! I am wondering where can I put a code and show up the total visited amount of my blog? Is it possible? thanks!
Do you mean the total visiter to your blog or the total visiter on a per post basis? Right now it works fine on a per post basis, that’s how I have my site setup. http://www.bleakgeek.com if you wish to take a look. Let me know how it goes : )
One major problem I see with this plugin is that one use can keep refreshing on the post and have the view count just keep going up.
I make a workaround for this; if a user has seen that post, it won’t increment it again. I.e. it has turned into “view per post” to “view per post per user” sort of thing.
See my post for info on how to edit it, or if the author would like to add it to his plugin.
Jonathan, how do I create a list of the most viewed posts?
Follow the instructions that come with the plugin and it tells you how.
test
Another test
the most important plugin for wordpress
thanks
Hi,
im using this plugin and I was wondering,It counts the views to every single page on my site and displays them in the top list,including the contact us section about ect… is there any way to filter the pages you want it to count?
Anyays to filter the pages you want counted?
It adds two points per visit in my blog! how can it be possible
I have checked and i only have add_count once
i cant find
in my index.. im using wordpress 2.1
For wordpress 2.1 onwards, add these codes
no permalinks:
0) { add_count($p);}?>
using permalinks:
0) { add_count($id);} ?>
in single.php of your themes folder, under
Hope this helps.
Is there a way to set it to a different number than 10? say, 15 or 20?
Thanks.
how to add table using phpadmin?