Get the Official WPSaviour App Now!


Useful Alternatives to the Dreaded Monthly Archive Links

WordPress sites’ sidebars, you’ll probably see the monthly archive links make an appearance. These are a list of links that categorize your post by month. If you want to get more specific, you can even group the posts by week or even day. Unless you’re using widgets, these lists are output using the wp_get_archives function. Here are some examples:

  • <?php wp_get_archives(); ?> – Lists the monthly archives (no parameters needed, it’s monthly by default)
  • <?php wp_get_archives('type=weekly'); ?> – Lists the weekly archives
  • <?php wp_get_archives('type=daily'); ?> – Lists the daily archives
  • Bonus: <?php wp_get_archives('type=yearly'); ?> – Lists the yearly archives

So what’s the problem? Well, depending on the site, monthly archive links aren’t very useful to your visitors. I mean, how many times have you visited a site and said “Hmm…I want to check out some posts written in January 2008”?

Probably never, and these links waste valuable space in your sidebar (or footer, whatever) that could be occupied by more useful links.

In this post, we’ll go over how to insert the following into your WordPress theme, including a widget alternative (if available):

  • Popular post links (three separate methods)
  • Featured articles/links using the Blogroll
  • Recent post links

There are a few methods to get a link list of popular/useful posts. Here they are:

Popular Posts by Comments

Sometimes the quantity of comments is a good way to gauge a post’s popularity. If you want to generate a list of links with your most commented posts, here’s the code for that:

First, paste the following function in your functions.php file:

function popularPosts($num) {
    global $wpdb;

    $posts = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $num");

    foreach ($posts as $post) {
        $id = $post->ID;
        $title = $post->post_title;
        $count = $post->comment_count;

        if ($count != 0) {
            $popular .= '<li>';
            $popular .= '<a href="' . get_permalink($id) . '" title="' . $title . '">' . $title . '</a> ';
            $popular .= '</li>';
    return $popular;

Then paste the following into your sidebar (or wherever you want a list of popular posts by comments):

     <?php echo popularPosts(10); ?>  

You can change the “10” to however many posts you want. I’m assuming you already have CSS in place in your theme for lists like this, so I won’t go over any CSS styling.

Source: How to List Your Most Popular Posts in WordPress

“Currently Hot” List

– This is a relatively new method of generating a list of popular posts. It requires you use the WordPress.com Stats plugin. Here’s the code:

	if (function_exists('stats_get_csv')) {
		$top_posts = stats_get_csv ('postviews', 'days=7&limit=8');

		if (count($top_posts) > 0) {
			echo '<ol>';
			foreach ($top_posts as $p) {
				<li><a href="<?php echo $p['post_permalink']; ?>"><?php echo $p['post_title']; ?></a></li>
			echo '</ol>';


Remember: You need the WordPress.com stats plugin activated for this code to work. If you just installed it, you should probably leave it on for a few days to collect enough relevant data before using it.

If you want to hide the smiley face added by the plugin, make sure you hide it the right way.

Hint: Change the “ol” tags to “ul” if you want an unordered list instead of a numbered list.

Source: Quick and Easy Popular Posts for Your WordPress Blog

Featured Articles with Blogroll

Using WordPress’ built-in blogroll functionality, you can manually select a link to whichever posts you want. This is probably the most flexible way since you have the most control over how your links are displayed, and they don’t even have to be on your site.

You can also categorize your links and list them all in separate lists, using just one line of code with the built-in wp_list_bookmarks function.

<?php wp_list_bookmarks('title_before=<h3>&title_after=</h3>&category_before=&category_after='); ?>

This will output all your blogroll list categories with “h3” titles. Depending on your sidebar’s markup, you may want to add code to be displayed before and after each list.

If you want to exclude any categories, you can use the exclude_category parameter with a comma-separated list of link category IDs.

Recent Post Links

This is something pretty simple that I’ve gone over before. Using the same wp_get_archives function we went over above, you can modify to get a list of recent posts.

<?php wp_get_archives('title_li=&type=postbypost&limit=10'); ?>

The type=postbypost is the type to use. If you have a ton of posts, I’d recommend using a limit so all of your posts don’t show up.

Download The WPSaviour App Now

Related posts
Best WordPress PluginsBlog

WordPress 5.4 Will Add Lazy-Loading to All Images

Beginner’s GuideBlog

How to Add a Preloader Animation to WordPress (Step by Step)


Install WordPress On Ubuntu Locally With LAMP


Theme Customizer Boilerplate – Conditional Options, Child Themes and Plugins

Sign up for our Newsletter and
stay informed

Leave a Reply

Your email address will not be published.