Can Someone Help Me Write This Loop?

4 replies
I want to hack my Wordpress MU setup so that it rotates through 31 different default themes...one for every day of the month.

I read elsewhere that you can change the default theme by finding this line of code in the upgrade-schema.php file:

Code:
add_option('template', 'default');
add_option('stylesheet', 'default');
...and then just changing it from "default" to the name of whatever theme you want to be the new default theme.

I'd like to get my hands on a php loop that will basically do the following:

if(day-of-the-month = 1, return "Blue Theme"}
else if {day-of-the-mont = 2, return "Red Theme"}
else if {day-of-the-month = 3, return "Green Theme"}
etc...

Can someone get me started on this? I know it's crazy simple, but the small amount of tinkering with php that I do has gotten me nowhere so far.
#loop #write
  • Profile picture of the author Manfred Ekblad
    date("j",time())

    that will get you the "Day of the month without leading zeros"

    PHP date function

    so... something like:

    $dayofmonth = date("j",time());
    $theme = "";
    switch ($dayofmonth) {
    case 1:
    $theme = "Blue Theme";
    break;
    case 2:
    $theme = "Red Theme";
    break;
    }
    return $theme; //if put in a function

    you might proofread that b4 u put it into production :p
    {{ DiscussionBoard.errors[2025413].message }}
    • Profile picture of the author Christopher Airey
      Less code:


      <?php

      $templates[0] = 'firstTheme';
      $templates[1] = 'secondTheme';
      $templates[30] = 'thirtyFirstTheme';

      $day = date('j');

      add_option('template', $templates[$day-1]);

      ?>
      {{ DiscussionBoard.errors[2025897].message }}
  • Profile picture of the author Manfred Ekblad
    Without testing your code, shouldn't the -1 be inside the [$day]..?

    since $templates[$day] will return the template name (a string), so doing -1 on that doesn't make sense. But since u use a zero-based array for the days, it would make sense to put the -1 inside the [$day]... as in [$day-1].
    {{ DiscussionBoard.errors[2026120].message }}
    • Profile picture of the author Christopher Airey
      Yeah you're right. The dumb code tags on here didn't work so I had to retype that three times.
      {{ DiscussionBoard.errors[2027980].message }}

Trending Topics