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?

1 Answer 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);
  • Thanks for helping again, and I'm sure this is a silly question, but how do I get this into a proper query? I'm trying <?php if (is_day("Today is a good day.")); ?> which I'd hope would output Today is a good day. on individual archive pages, but it's doing nothing.
    – user3903
    Commented Mar 26, 2011 at 0:10
  • Ah, edited my answer. These conditional statements just return a true/false value, so after testing the conditional, you have to include a block (usually within {} curly braces) with the action you want to take if the test returns true. Commented Mar 26, 2011 at 0:26
  • 1
    Added a ; at the end, and everything's starting to come together.
    – user3903
    Commented Mar 26, 2011 at 15:28
  • Aha. I must've been typing too fast. I'll fix that in my answer. Commented Mar 26, 2011 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.