Wordpress wp_get_archives for a specific category


/ Published in: PHP
Save to your folder(s)

Get Wordpress wp_get_archives for a specific category... by default it sghows all categorys


Copy this code and paste it in your HTML
  1. XXXXXX shows the two items that need editing, category ID and URL path
  2.  
  3. ===============================================================
  4.  
  5. <?php
  6. global $wpdb, $wp_locale;
  7. $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
  8. WHERE $wpdb->posts.post_status = 'publish'
  9. AND $wpdb->posts.post_type = 'post'
  10. AND $wpdb->term_taxonomy.term_id = XXXXXX30XXXXXXX
  11. AND $wpdb->posts.ID = $wpdb->term_relationships.object_id
  12. AND $wpdb->term_taxonomy.term_id = $wpdb->term_relationships.term_taxonomy_id
  13. GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC";
  14. $arcresults = $wpdb->get_results($query);
  15. foreach ($arcresults as $arcresult):
  16. $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);?>
  17. <li><a href="<?php bloginfo('url') ?>XXXXX/category/blog/XXXXXXX<?php echo $arcresult->year; ?>/<?php echo str_pad($arcresult->month, 2, '0', STR_PAD_LEFT); ?>"><?php echo $text; ?> </li>
  18. <?php endforeach; ?>
  19.  
  20.  
  21. THIS NEEDS ADDING TO functions.php
  22.  
  23. ===============================================================
  24.  
  25.  
  26.  
  27. /**
  28. * Adds a pretty "Continue Reading" link to custom post excerpts.
  29. *
  30. * To override this link in a child theme, remove the filter and add your own
  31. * function tied to the get_the_excerpt filter hook.
  32. *
  33. * @since Twenty Ten 1.0
  34. * @return string Excerpt with a pretty "Continue Reading" link
  35. */
  36. function twentyten_custom_excerpt_more( $output ) {
  37. if ( has_excerpt() && ! is_attachment() ) {
  38. $output .= twentyten_continue_reading_link();
  39. }
  40. return $output;
  41. }
  42. add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );
  43.  
  44.  
  45.  
  46. function extend_date_archives_flush_rewrite_rules(){
  47. global $wp_rewrite;
  48. $wp_rewrite->flush_rules();
  49. }
  50. add_action('init', 'extend_date_archives_flush_rewrite_rules');
  51.  
  52. function extend_date_archives_add_rewrite_rules($wp_rewrite){
  53. $rules = array();
  54. $structures = array(
  55. $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_date_permastruct(),
  56. $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_month_permastruct(),
  57. $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_year_permastruct(),
  58. );
  59. foreach( $structures as $s ){
  60. $rules += $wp_rewrite->generate_rewrite_rules($s);
  61. }
  62. $wp_rewrite->rules = $rules + $wp_rewrite->rules;
  63. }
  64. add_action('generate_rewrite_rules', 'extend_date_archives_add_rewrite_rules');

URL: http://wordpress.stackexchange.com/questions/13968/wp-get-archives-for-a-specific-category

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.