Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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);
}
share|improve this answer
    
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 Mar 26 '11 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. –  goldenapples Mar 26 '11 at 0:26
1  
Added a ; at the end, and everything's starting to come together. –  user3903 Mar 26 '11 at 15:28
    
Aha. I must've been typing too fast. I'll fix that in my answer. –  goldenapples Mar 26 '11 at 17:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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