For some reason, WordPress’ “wp_get_archives()” function does not allow us to include or exclude categories by default. This is weird, because many other WordPress hooks include this basic functionality.
Thankfully, after struggling for a bit today, I discovered this plugin that solves the issue. It hooks directly into the WordPress core, so customizing is a breeze! Simply add “cat=5” (with the number “5” being the id of the category you want to include) to the “get_archives” parameters in your template file! It’ll look like this: <?php wp_get_archives(‘cat=5’); ?>
Pretty cool, eh?
16 Comments
More posts from themightymo.com
How to Connect a GoDaddy Site to ManageWP
GoDaddy owns ManageWP, and, strangely, they make it very difficult to add GoDaddy-managed WordPress sites to their ManageWP service. Thankfully, there’s a quick workaround: Visit https://yoursite.com/wp-admin/plugins.php?showWorker=1 — This will make the ManageWP “Worker” plugin visible. Copy the connection info from the ManageWP Worker plugin. Add the site per-normal on ManageWP. That’s it! I hope this…
How to check if your current page is the wp-login.php page
I realized this morning that my TMM Maintenance Mode WordPress plugin had a bug that was causing the wp-login.php page to be inaccessible. The solution was to write a simple function that checks whether or not we’re currently on a login page, and then add a call to that function in my code. Here’s the…
WooCommerce Product Image Gallery Not Loading with WP Rocket Active
Today I updated a WooCommerce site, and everything worked fine, except for the images on product pages – they were not displaying at all. After a lot of trial & error, I realized that WP Rocket was to blame. I’m not sure exactly what the issue was (though my hunch is that it had to…
thanks a lot!!!!!
No problemo, Danilo! 🙂
This is definitely what I was looking for — but it doesn’t seem to work with permalinks.
@Courtney – What do you mean? Permalinks to blog posts?
Hmm, maybe I described that wrong.
But the real issue is that, while it does filter down the archives list correctly it doesn’t display the contents for a particular month in that list.
The plugin creates this link for September 08 — http://myurl.com/2009/09/?cat=4 — but if I click on it it displays as http://myurl.com/category/cats/ (“cats” being category with ID of 4). And it displays all entries for that category, not just September 2008.
I guess what I’d really like is if it did something like:
http://myurl.com/2009/09/category/cats/.
P.S. Shoot, I shouldn’t have used “cats” as my arbitrary category name (“cats” and “category” might be confusing)… Insert “dogs” or whatever category name makes the most sense to understand the scenario.
Hi Courtney, wondering if you figured out the permalinks issue with this plugin. I’ve been having the same problem I think.
@Courtney – I see what you are talking about now, but unfortunately, I don’t know how to solve the problem. Perhaps you can find some help on the WordPress.org forums.
Not too sure if there has been a recent update to the plugin, but to make it work with permalinks, just go to the plugin settings page (Settings > Kwebble) and click on “Disable canonical URLs.” Then update. Works fine now for me with neat url permalinks.
You might already know about this, but thought I’d comment about it just in case.
It doesn’t work.
If I click on the month, the actual page reloads and it doesn’t goes to the archive.php to list the posts.
Thanks a lot …………………………….
Great. Thanks
Does this plug-in work with thesis theme? I tried but not working.
Here is my code:
function posts_nav() {
echo ‘Blog‘;
wp_get_archives(‘cat=5’);
echo ”;
}
add_action(‘thesis_hook_last_nav_item’,’posts_nav’);
?>
@Yub – I have not tried this in the Thesis theme.
Could this also work if you passed an author ID through the wp_get_archives?
Thanks
@Grant – I don’t know. Please give it a try and let me know!