Return to Snippet

Revision: 59507
at September 13, 2012 02:12 by i-am-andy


Initial Code
XXXXXX shows the two items that need editing, category ID and URL path

===============================================================

					<?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 = XXXXXX30XXXXXXX
                        AND $wpdb->posts.ID = $wpdb->term_relationships.object_id
                        AND $wpdb->term_taxonomy.term_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') ?>XXXXX/category/blog/XXXXXXX<?php echo $arcresult->year; ?>/<?php echo str_pad($arcresult->month, 2, '0', STR_PAD_LEFT); ?>"><?php echo $text;  ?> </li>
                      <?php endforeach; ?>  


THIS NEEDS ADDING TO functions.php

===============================================================



/**
 * Adds a pretty "Continue Reading" link to custom post excerpts.
 *
 * To override this link in a child theme, remove the filter and add your own
 * function tied to the get_the_excerpt filter hook.
 *
 * @since Twenty Ten 1.0
 * @return string Excerpt with a pretty "Continue Reading" link
 */
	function twentyten_custom_excerpt_more( $output ) {
		if ( has_excerpt() && ! is_attachment() ) {
			$output .= twentyten_continue_reading_link();
		}
		return $output;
	}
	add_filter( 'get_the_excerpt', 'twentyten_custom_excerpt_more' );



function extend_date_archives_flush_rewrite_rules(){
	global $wp_rewrite;
	$wp_rewrite->flush_rules();
}
add_action('init', 'extend_date_archives_flush_rewrite_rules');

function extend_date_archives_add_rewrite_rules($wp_rewrite){
	$rules = array();
	$structures = array(
		$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_date_permastruct(),
		$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_month_permastruct(),
		$wp_rewrite->get_category_permastruct() . $wp_rewrite->get_year_permastruct(),
	);
	foreach( $structures as $s ){
		$rules += $wp_rewrite->generate_rewrite_rules($s);
	}
	$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_action('generate_rewrite_rules', 'extend_date_archives_add_rewrite_rules');

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

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

Initial Title
Wordpress wp_get_archives for a specific category

Initial Tags
date, wordpress, category

Initial Language
PHP