• Hello,

    I think this widget could use a post count next to each year and month, as an option. I have modified the code of the plugin on my own WordPress and thought others might need to as well.

    Bear in mind this is a quick edit that fits my particular needs, and could probably be optimised (starts at line 47, in micro-archive-widget/micro-archive-widget.php):

    $archives_params = array(
        'echo' => 0,
        'show_post_count' => 1
    ); // Added
    $archives = str_replace(' ',' ', wp_get_archives($archives_params)); // Edited
    
    preg_match_all('#<a href=\'(.+)\'>(.+) (\d+)<\/a> \((\d+)\)#', $archives, $matches); //Edited
    
    $elements = array();
    
    foreach ($matches[0] as $i => $match) {
        list($url, $month, $year, $postcount) = array($matches[1][$i], $matches[2][$i], $matches[3][$i], $matches[4][$i]); // Edited
        $elements[$year][$month][] = array('url' => $url, 'postcount' => $postcount); // Edited
    }
    
    echo '<ul>';
    
    foreach ($elements as $year => $months) {
        $year_post_count = 0;
        $year_html_output = '';
    
        foreach ($months as $month => $elemtparams) { // Edited
            foreach ($elemtparams as $elemtparam) { // Edited
                $year_post_count += $elemtparam['postcount'];
                $year_html_output .= '<li class="archive-micro-month"><a href="' . $elemtparam['url'] . '">' . $month . '</a> (' . $elemtparam['postcount'] . ')</li>'; // Edited
            }
        }
    
        echo '<li class="archive-micro-year"><a>' . $year . '</a> (' . $year_post_count . ')';
        echo '<ul>';
        echo $year_html_output;
        echo '</ul></li>';
    }
  • The topic ‘[Suggestion] Post count’ is closed to new replies.