X

Useful Alternatives to the Dreaded Monthly Archive Links

In a lot of 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) {
        setup_postdata($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):

<ul>
     <?php echo popularPosts(10); ?>  
</ul>

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:

<?php
	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>
<?php
			}
			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.

You can also use the “Recent Posts” widget, assuming your sidebar is widgetized.

Conclusion

I know on some sites, monthly archive links can be useful, like perhaps on a news site, or an “of the day” site (like for cartoons or recipes).

Some people glance at them just to see how long the blog has been active, it can help credibility (hint: add the show_post_count=1 parameter to show a post count next to monthly archive links).

Most of the time, however, it’s a waste of space. It can be replaced with some other much more useful links, like popular content or related posts that users would find more value in.

Any monthly archive links could be placed on a site map page and out of your sidebar.

In the comments, I’d be interested to hear your feedback. Do you use monthly archive links? When do you think they could be relevant? Do you have any other useful alternative examples?

Comments   Leave a Reply

  1. Hey nice post, been looking for something like this based on current data. What I need to find out is if I used a custom field which I use to display a thumbnail per post, how do I insert a function to pull the data from the field and then display it somewhere in the popular post?

  2. Tia - BizChickBlogs.com April 13, 2010 at 5:07 pm

    I agree w/ WP Splash. Finding other ways to navigate posts – beyond dated archives – in the sidebar is the way to go even for personal blogs. I personally like recent comments and recent posts, and popular posts by view (not comment).

    But, I do think that an Archives Page is OK. After all, I have one. lol It drives me insane if I can’t get to a list of everything on the blog I’m reading. It makes me wonder what they are hiding. 🙂

    Maybe I’m just nosy.

  3. Showing monthly or yearly archive is so old school. It’s from the days when weblogs were actually logs of your activities.

    It makes more sense now to let visitors find content by categories and tags, and other similar ways that utilize keywords rather than dates.

  4. There is a plugin – of course I can’t remember the name – that will show a list at the end of the post, of archived posts on this date (or close enough) from the past.

    On tech blogs, no this might not make so much sense. But on personal blogs, it is an interesting glimpse into what the author was writing about this time last year.

  5. Definatly going to add some of them to my sidebar on the theme I’m working on!
    Thanks

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!