• With wp_get_archives('type=monthly&show_post_count=1&echo=0') I can display monthly archive links like the following:
    <li><a href="blog/date/2009/07/" title="July 2009">July 2009</a>&nbsp;(1)</li>
    This is standard WordPress functionality.

    However, I would like to find a way to display the same information like this:
    <li><a href="blog/date/2009/07/" title="July 2009">July 2009&nbsp;(1)</a></li>
    with the monthly post count inside of the anchor tag.

    I can do this with categories in the following manner:
    foreach (get_categories(array('hide_empty'=>true)) as $category){$category_variable .= '<li><a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '&nbsp;(' . $category->count . ')</a></li>';}

    Is there any way do that for date archives? So far I am coming up empty.

    Any help is greatly appreciated!
    ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter grapepress

    (@grapepress)

    I figured a way to do it. I copied some of the WordPress core code and modified it (outside of the core) to do what I want:

    $how_many=6; //how many months to display
    $arcresults2=$wpdb->get_results("SELECT YEAR(post_date) AS 'year', MONTH(post_date) AS 'month', count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC LIMIT $how_many");
    foreach((array) $arcresults2 as $arcresult){
    	$url = get_month_link( $arcresult->year, $arcresult->month );
    	$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
    	$after = '&nbsp;(' . $arcresult->posts . ')';
    	$archive_variable .= '<li><a href="' . $url . '">' . $text . $after . '</a></li>';
    }

    Then I just echo $archive_variable;.

    If anyone has better ideas I am open to them.

    I made a custom function based on the wp_get_archives function from wp-includes/general-template.php. I simply replaced the “$after =” with “$text .=”

    Here’s an example:

    if ( $show_post_count )
    					$after = '&nbsp;('.$arcresult->posts.')' . $afterafter;

    becomes:

    if ( $show_post_count )
    					$text .= '&nbsp;('.$arcresult->posts.')' . $afterafter;
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display post count within link for monthly archives’ is closed to new replies.