Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been pulling my hair out on this one - I need to hard code in wp_get_archives() for a specific category into a template.

This post was useful:

Category Specific Archive

but, as with all the plugins I've found so far, they don't work with WP 3.1 (or you need to hack the core files which I obviously don't want to do).

Is there another solution I'm not aware of? Maybe a method by creating a separate loop?

THanks for any pointers

osu

share|improve this question
add comment

3 Answers

Take a look at Scribu's Smart Archives Reloaded plugin which allows you to display a list of posts grouped by year and month.

And to limit the archives by category is as simple as this:

smart_archives( '', 'category_name=category_name' ); 
share|improve this answer
add comment

I did this in a relatively complicated way using a custom query. I did not know about Smart Archives Reloaded so I wrote code myself. But it works. Replace your category ID for "term_taxonomy.term_id"

<?php
                     global $wpdb, $wp_locale;
                    $query = "select YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts from $wpdb->posts,  $wpdb->term_taxonomy, $wpdb->term_relationships 
                        WHERE $wpdb->posts.post_status = 'publish' 
                        AND $wpdb->posts.post_type = 'post'
                        AND $wpdb->term_taxonomy.term_id = 11
                        AND $wpdb->posts.ID = $wpdb->term_relationships.object_id
                        AND $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id
                     GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC"; 
                     $arcresults = $wpdb->get_results($query); 
                    foreach ($arcresults as $arcresult): 
                    $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);?>
                    <li><a href="<?php bloginfo('url') ?>/[your_category_base]/[your_category_name]/date/<?php echo $arcresult->year; ?>/<?php echo str_pad($arcresult->month, 2, '0', STR_PAD_LEFT); ?>"><?php echo $text;  ?> </li>
                      <?php endforeach; ?> 

Writing this I was helped by looking at http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/general-template.php where wp_get_archives is defined.

And used the code found here (put in functions.php): http://snipplr.com/view.php?codeview&id=17432 to create permalinks for archives for one category in the form of http://example.com/category_base/category_name/date/YYYY/MM

share|improve this answer
add comment

Perhaps use query_posts to generate your query and then use a custom loop.

http://codex.wordpress.org/Function_Reference/query_posts

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.