WordPress Snippet: Display Posts by Tag Frequency
Blogs just aren’t the same as they used to be. In the old days a blog was characterized by time and personality—chronology was important, and you read the blog because of the author, not the information he could give you.
Nowadays blogs are used more for short bursts of information about a single topic—typically a blogger’s expertise. The personality behind a site barely matters. “Content is king!” as you may recall.
So if chronology is no longer important, why post by date? I think part of the answer is that WordPress displays dates by default in most themes. Let me propose an alternative way of displaying content in WordPress. By tag frequency.
Making tags useful
Tags provide wonderful meta information about a post, but sadly this information is typically relegated to an ugly list in the sidebar. I say, if you’re going to go to the work of tagging all those posts, you had better use those tags for something useful!
By adding a couple snippets outside “The Loop” in WordPress you can display N number of posts by X tag. Here is an example to help make it a little more clear:
Imagine you have 20 posts tagged Home and Garden, 10 tagged Clearance, and 13 tagged Hardware. With a bit of PHP we can get WordPress to display posts from each tag in order of most popular to least popular. We can even take it a step further and limit the number of tags to display. The end result might look something like this:
HOME AND GARDEN * Tag 1 Post 1 Title * Tag 1 Post 2 Title * Tag 1 Post 3 Title * Tag 1 Post 4 Title HARDWARE * Tag 2 Post 1 Title * Tag 2 Post 2 Title * Tag 2 Post 3 Title * Tag 2 Post 4 Title CLEARANCE * Tag 3 Post 1 Title * Tag 3 Post 2 Title * Tag 3 Post 3 Title * Tag 3 Post 4 Title
Now that is a usable list of tags that makes the content readily available. A great side effect of displaying posts by tag frequency is that your site become much more dynamic. For example, maybe you go to a plumbing conference and blog 30 posts about it, all tagged Plumbing. The content on the site will automatically start displaying the posts tagged with Plumbing at the top of the list. I call it the “bubbling” homepage.
Enough rambling, here’s the code:
have_posts() ) :?>