Subscribe to the RSS Feed
FreeWordpressThemes.us
Free WordPress Tutorials and Themes.

Useful Alternatives to the Dreaded Monthly Archive Links

March 27th, 2010 by admin

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.

If you don’t know how to use the blogroll feature, I found this pretty nice screencast on WordPress.tv (try watching it in full screen mode).

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?

Related posts:

  1. The Easy Way To Display Recent Posts in WordPress
  2. The Ultimate Guide to WordPress Conditional Tags
  3. Add a Widgetized Footer to Your WordPress Theme
Written by - Visit Website

Posted in Theme Labs

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.