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 am new to WordPress and I would appreciate some cool advice here.

I have changed the header.php file in the Editor to include an image. I wonder if it is possible to automatically display one of 9 possible images depending on the date (ie. rotate them)

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The following code will cycle between the 9 pics. 1st day of the year = pic0, 2nd = pic1...359th = pic9, 360th = pic0, etc.

<?php
$pic_array = array(
    'pic0',
    'pic1',
    'pic2',
    'pic3',
    'pic4',
    'pic5',
    'pic6',
    'pic7',
    'pic8',
);

$d = (int) date('z') % 9;
$todays_pic = $pic_array[$d];
echo $todays_pic;

Hopefully you're not changing a parent theme's header.php!

share|improve this answer
    
Thanks ! Although it is probably not a perfect rotation, since on 31 of a month it will display image #4 and on the next day it will display image #1, however, it works for me. What do you mean "Hopefully you're not changing a parent theme's header.php!" ? –  Wartin Jan 18 '13 at 2:25
    
Actually, my code rotation is based on the days of the year. So excess repeats will only occur on pic0-pic6 once per year, e.g, day 365 will be pic6 then day 1 will roll back to pic0 (but you probably won't be using same setup that long!) RE: not changing parent theme's header.php, soon as you update (on purpose, or by mistake) you'll lose any cusomizations. See the WordPress Codex on making child themes, pretty painless. There's even a plugin to automate it for you. –  akTed Jan 18 '13 at 2:32
    
The reason I made it based on the year instead of the month is because of February. 28th would be pic0 and so would March 1st. If we were in March right now I probably would've used by month instead. :) –  akTed Jan 18 '13 at 2:40

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.