PDA

View Full Version : Rotate styles by day.


Brad
11-21-2002, 04:30 AM
Say i have 7 styles made for my forums, they only differ in color. Now say i want style 1 to display on sunday, style 2 on monday etc. Would it be possible to write a script that would automaticly change the default style at 12 midnight everyday?.

Logician
11-21-2002, 08:25 AM
There are some issues to be solved like if your style will overwrite forum's forced styles or user's custom style but assuming answers are no for both here is your code:

edit global.php (in forum dir, not in Admin dir!), find:

// is style in the forum/thread set?
if (isset($codestyleid) and $codestyleid!=0) {
$styleid=$codestyleid;
} else {

// Will look in the user info for a style
if ($bbuserinfo['styleid']!=0) { //style specified
$styleid=$bbuserinfo['styleid'];
} else { //no style
$styleid=1;
}


Replace it as:

// is style in the forum/thread set?
if (isset($codestyleid) and $codestyleid!=0) {
$styleid=$codestyleid;
} else {

// Will look in the user info for a style
if ($bbuserinfo['styleid']!=0) { //style specified
$styleid=$bbuserinfo['styleid'];
} else { //no style
$styleid=date("w",time())+1;
}


Now the hack will make these styles default automatically everyday at 12:00 AM (According to the server time!):
Sunday => Style 1
Monday => Style 2
..
..
Saturday => Style 7

Enjoy.. :glasses:

Brad
11-21-2002, 10:20 AM
Thanks man, ill make sure to use this when we introduce the new styles next week :)

Brad
11-21-2002, 10:23 AM
Last question, seeing how the code is style 1 (sunday) would be named '0' correct?

Logician
11-21-2002, 11:10 AM
I didn't get the question

Brad
11-21-2002, 11:43 AM
Well seeing out its using the date function i looked it up, heres the quote of what i read:

w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday)

but now i see a +1 in your code.

Heres the question, what would the name of the styles be? 1, or style 1? Im not clear on how it works. Again thanks for all your help

Logician
11-21-2002, 12:18 PM
style name does not matter. You can name styles in anyway you like.

My code is interested in style ids, not names. So it will display styleid 1 in sunday and 2 in monday etc.

If your styles are not in order, instead of $styleid=date("w",time())+1;
you can use this code:

if (date("w",time())==0)
{
$styleid=X; //enter id for sunday
}
elseif (date("w",time())==1)
{
$styleid=Y;
//enter id for monday
}
..
..
elseif (date("w",time())==6)
{
$styleid=Q;
//enter id for saturday
}

see? ;)

Brad
11-21-2002, 12:28 PM
Yea, i relized it was id based when i was on my way to breakfast, thanks again :)