Matt's Blog

Displaying Your Top 10 Posts

May 27th, 2007 at 2:39 PM (17 years ago) by Matt Freedman

If you use WordPress, you have probably wondered if you can display your Top 10 Most Popular Posts before. Well, you can do just that by installing a Plugin that will record the number of hits an Article has. Then, uploading a simple PHP file that you can download for free.

The Plugin is WP-PostViews. The Plugin is free and is released under the GNU General Public License. So, simply install that Plugin by downloading it, extracting it and uploading it to /wp-content/plugins/.

Now this is where 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 it’s more “WP-Friendly” you could say. So, you can download my script here. The script is licensed under the GNU General Public License. Now, all you have to do is download that file (or copy and paste it into a new file) and name it something like topposts.php, or anything really, as long as it ends in .php, and not .txt. You may need to change the following lines, depending on where your WordPress installation is installed and where you put the script:

require_once('wp-config.php');
require_once('wp-includes/wp-db.php');

Then, upload the script. If you don’t want it to be a Top 10, you can change the value of $limit to something like 5 to have a Top 5.

You can see my Top 10 Posts here.

Get it? Got it? Good.

Enjoy. 😀

Leave a Reply

Quote selected text

Leave the following field empty: