WordPress Top 10 Posts Code

Published on May 23, 2007   //  Development

Top 10 Blog PostsEver wonder what your top 10 posts are? We installed the plugin WP-PostViews which keeps track of how many people have viewed each and every post.

The plugin does provide you with a way to view the top 10 posts which I am sure most people who install this would like to know. The problem is it needs to be called from within a page on your blog.

The application for this is that a user would want to display their top viewed post on their main site and not their blog.

I created this small script to view it on just a blank page. You can use this script yourself if you wish to view your Top 10 Posts.

13 Comments to “WordPress Top 10 Posts Code”

  • Well there is a major problem with your blog (as I think) there is no contact me form and no About me page. I know you can’t actually put the contact me here Gary but an About page can do more justice to readers

  • I am not sure how this relates to this topic.

    There is no contact me or about us because this is not a personal blog. Those details can be found on our site already at http://www.bluefur.com.

    Also on a side note I am not the only one that blogs here. If you view the writters of the blog you will see we have 5 people that blog.

  • I have add these to the Navigation.

    Thanks for the suggestion.

  • You should just include wp-config.php and wp-includes/wp-db.php. Then, you can use built-in WP Database stuff. Here’s the file with a little bit of editing (I haven’t tested it, though):

    http://mattsblog.ca/topposts.txt

  • blogadmin, phpguru, brandit, Rhetorical… and who else? Or, are you counting Matthew Schmoll?

  • Okay, I tested it, and fixed it. It works now! Here it is: :D

    http://mattsblog.ca/topposts.txt

    (feel free to use it and distribute it, if you want :) )

  • Is there a working copy on your site?

    I couldn’t find it ;)

  • No, there wasn’t. I didn’t even have the Plugin installed. :P

    I was testing it on localhost.

    Well, I can now say it works with WordPress 2.1.3 and 2.2.

    You can now see a working copy on My Blog here:

    Matt’s Blog Top 10 Posts

  • That looks like a top 2.

  • I only installed the Plugin a couple of minutes ago, so once it’s been installed for a little while longer, it’ll be a Top 10. Trust me, I’ve tested it. :P

  • I updated the file again, so that the results are in a numbered list.

    http://mattsblog.ca/topposts.txt

  • Updated, again… I’ve add no-cache headers to it.

    http://mattsblog.ca/topposts.txt

  • [...] my script comes in. Okay, it isn’t totally my script. It’s a modified version of the Script BlueFur released for this same purpose. Except, I cleaned it up a bit and made it so it used WordPress functions, so [...]