This has really been driving me mad for a while now, so I'm hoping someone can help. I'm trying to use wp_get_archives()
to display a list of links to yearly archives that show posts within the current category.
Importantly, I'm trying to do this without a plugin and just use the functions file or even a WP_Query
loop.
Example
Imagine I have the following categories all filled with posts:
Exhibitions (parent)
--Current (child)
--Past (child)
Artworks (parent)
--Recent (child)
--Featured (child)
--Old (child)
What I'm trying to do is essentially this:
/* Get current Cat ID */
function getCurrentCatID() {
global $wp_query;
if(is_category() || is_single()){
$cat_ID = get_query_var('cat');
}
return $cat_ID;
}
$currentCat = getCurrentCatID();
wp_get_archives('type=yearly&cat=$currentCat'); // But, you can't filter this by category it seems
So, if I view the 'Exhibitions' category (which uses category.php), wp_get_archives()
would show links for 2012, 2011, 2010 etc.
When I click 2011, I would see posts that are in the category 'Exhibitions' AND it's child categories (also important).
I've found this post which might hold the answer: Exclude Category From wp_get_archives?
But I don't know how I would use the current category being viewed within filters mentioned in the post nor how I would add multiple categories to it (i.e. the parent category plus it's children).
Any help massively appreciated.
Osu