Displaying year, month and day archives differently

I’d like to display daily archives differently than monthly/yearly archives. How do I check to see if the archive template is being pulled for a daily archive vs. a monthly/yearly archive?

Related posts

Leave a Reply

1 comment

  1. Conditional tags FTW.

    • is_month() : Currently viewing a monthly archive
    • is_day() : Currently viewing a single day archive
    • is_year() : Currently viewing a yearly archive
    • is_time() : Currently viewing a time-based archive (hourly, minute, or even seconds)

    So to test for each of these conditions, add something like this to your archive.php (or whatever template is being used for your archive pages):

    // Check what posts were returned in order to find what date the archive is for
    global $posts; 
    $archivedate = strtotime( $posts[0]->post_date);
    if (is_day()) {
        echo "Daily archive: ".date('m/d/Y', $archivedate);
    } else if (is_month()) {
        echo "Monthly archive: ".date('F Y', $archivedate);
    } else if (is_year()) {
        echo "Yearly archive: ".date('Y', $archivedate);
    }