To accomplish what you need, you need to modify Wordpress rewrites to be able to capture year / month / etc data for a personalized message type.
You can do this with the following code:
function cpt_rewrite_rules($wp_rewrite) { $rules = cpt_generate_date_archives('news', $wp_rewrite); $wp_rewrite->rules = $rules + $wp_rewrite->rules; return $wp_rewrite; } add_action('generate_rewrite_rules', 'cpt_rewrite_rules'); function cpt_generate_date_archives($cpt, $wp_rewrite) { $rules = array(); $post_type = get_post_type_object($cpt); $slug_archive = $post_type->has_archive; if ($slug_archive === false) return $rules; if ($slug_archive === true) { $slug_archive = $post_type->name; } $dates = array( array( 'rule' => "([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})", 'vars' => array('year', 'monthnum', 'day')), array( 'rule' => "([0-9]{4})/([0-9]{1,2})", 'vars' => array('year', 'monthnum')), array( 'rule' => "([0-9]{4})", 'vars' => array('year')) ); foreach ($dates as $data) { $query = 'index.php?post_type='.$cpt; $rule = $slug_archive.'/'.$data['rule']; $i = 1; foreach ($data['vars'] as $var) { $query.= '&'.$var.'='.$wp_rewrite->preg_index($i); $i++; } $rules[$rule."/?$"] = $query; $rules[$rule."/feed/(feed|rdf|rss|rss2|atom)/?$"] = $query."&feed=".$wp_rewrite->preg_index($i); $rules[$rule."/(feed|rdf|rss|rss2|atom)/?$"] = $query."&feed=".$wp_rewrite->preg_index($i); $rules[$rule."/page/([0-9]{1,})/?$"] = $query."&paged=".$wp_rewrite->preg_index($i); } return $rules; }
You will notice that I have hard-coded news in $rules = cpt_generate_date_archives('news', $wp_rewrite); parts of the code. You can change this as needed.
With this code, you can go to http://yoursite.com/news/2013/02/ and get a list of archives for this particular type of message for that particular time.
For completeness, I'll tell you how to create a monthly archive widget to use this.
function get_cpt_archives( $cpt, $echo = false ) { global $wpdb; $sql = $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_type = %s AND post_status = 'publish' GROUP BY YEAR($wpdb->posts.post_date), MONTH($wpdb->posts.post_date) ORDER BY $wpdb->posts.post_date DESC", $cpt); $results = $wpdb->get_results($sql); if ( $results ) { $archive = array(); foreach ($results as $r) { $year = date('Y', strtotime( $r->post_date ) ); $month = date('F', strtotime( $r->post_date ) ); $month_num = date('m', strtotime( $r->post_date ) ); $link = get_bloginfo('siteurl') . '/' . $cpt . '/' . $year . '/' . $month_num; $this_archive = array( 'month' => $month, 'year' => $year, 'link' => $link ); array_push( $archive, $this_archive ); } if( !$echo ) return $archive; foreach( $archive as $a ) { echo '<li><a href="' . $a['link'] . '">' . $a['month'] . ' ' . $a['year'] . '</a></li>'; } } return false; }
To use this function, simply put the pool of a custom message type, that is: get_cpt_archives( 'news' ) . This will return an array of unique Year / Dates / Links, i.e.:
Array ( [0] => Array ( [month] => February [year] => 2013 [link] => http:
You can skip them using foreach and output them foreach you want.
Alternatively, you can use get_cpt_archives( 'news', true ) , which automatically sounders every element enclosed in a <li> link associated with its specific archive.
Formatting the output is not exactly what you wanted, so you will have to tweak it a bit to display it in
Year Month Month Year Month
which you need.
Hope this helps.