Support » Plugins » archives – current year in months, previous by year

  • Resolved beyondelsewhere

    (@beyondelsewhere)


    I have searched the forums, but I couldn’t find a question quite like I have. So I thought I’d shoot this out there.

    I would like my Archives on my sidebar to show the current year by month, but the previous years just by year. I am not sure how to do that.

    jan 07
    feb 07
    etc
    and then just
    2006
    2005
    etc.

    Can that be done? Or am I just a hopeless dreamer? 🙂

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Maybe not exactly what you want but could you find acceptable, two instances of the template tag, wp_get_archives in your sidebar?

    First one:
    <?php wp_get_archives('type=monthly&limit=12'); ?>

    Second one:
    <?php wp_get_archives('type=yearly'); ?>

    Thread Starter beyondelsewhere

    (@beyondelsewhere)

    Good enough for me! I can survive with what that looks like. It makes my sidebar less cluttered with stuff, so, thank you VERY much!! 🙂

    beyondelsewhere.ca (in case you wanted to take a looksee!)

    Nice work.

    I’ll marked this resolved.

    Michael,

    I wonder if there’s a better way to do this – I would really just like to show the current year by month and previous years by year

    2008
    -month
    -month
    -month
    2007
    2006

    if you use the solution you gave you see 2008 twice

    I think this is what you want:

    <ul>
    
    <?php wp_get_archives('type=yearly&limit=1'); ?>
    
    <ul>
    	<?php wp_get_archives('type=monthly&limit='.date('m').'&show_post_count=1'); ?>
    </ul>
    
    <?php
    $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC");
    unset($years['0']);
    foreach($years as $year) :
    ?>
    
    <li><a href="<?php echo get_year_link($year); ?>" title="<?php echo $year; ?>"><?php echo $year; ?></a></li>
    
    <?php endforeach; ?>
    
    </ul>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘archives – current year in months, previous by year’ is closed to new replies.