I need the ability for a site I am working on to show different content depending on the month. The site is for a kids activity camp, so they have different content depending on the holiday period eg. February half term, Easter, May half term, summer, October half term.
The current site you have to login from the front page then once logged in it needs to direct the user to the correct holiday period content.
Is this possible using PHP or perhaps Jquery?. I really hope someone can help me.
Also the following switch() statement that can include related “month” files which may be PHP, CSS, HTML, etc
Try this:
$month = date('n'); // 4 == April, 5 = May, etc // no leading zero
switch( $month ){
case 1 : include 'january.php'
break;
case 2 : include 'february.php'
break;
case 3 : include 'march.php'
break;
case 4 : include 'april.php'
break;
case 5 : include 'may.php'
break;
case 6 : include 'june.php'
break;
case 7 : include 'july.php'
break;
case 8 : include 'august.php'
break;
case 9 : include 'september.php'
break;
case 10: include 'october.php'
break;
case 11: include 'november.php'
break;
case 12: include 'december.php'
break;
}
This then takes them to the content of the site with all the navigation etc.
Do I add the month content switcher to index2.php?
When I added this I get lots of syntax errors
<?php
$month = date('n'); // 4 == April, 5 = May, etc // no leading zero
switch( $month ){
case 1 : include 'january.php'
break;
case 2 : include 'february.php'
break;
case 3 : include 'march.php'
break;
case 4 : include 'april.php'
break;
case 5 : include 'may.php'
break;
case 6 : include 'june.php'
break;
case 7 : include 'july.php'
break;
case 8 : include 'august.php'
break;
case 9 : include 'september.php'
break;
case 10: include 'october.php'
break;
case 11: include 'november.php'
break;
case 12: include 'december.php'
break;
}
?>
Really hope someone can assist and help me to get this work.
I cannot get any of these to work. As I mentioned once a user has logged in at the moment it diverts them to index2.php.
Depending on the month of the year I need the content to be displayed automatically for a particular month, May, June etc.
I added this to the top of index.2php HTML
<?php include strtolower(date('M')).'may.php';?>
But it did not display the May content. I need the process to be automatic, I don’t know PHP very well so please forgive my ignorance. I am more than happy to post a link through PM if that helps?
Look forward to hearing from you guys as I really need to get this to work.
<?php
$month = date('5'); // 4 == April, 5 = May, etc // no leading zero
switch( $month ){
case 1 : include 'january.php';
break;
case 2 : include 'february.php';
break;
case 3 : include 'march.php';
break;
case 4 : include 'april.php';
break;
case 5 : include 'may.php';
break;
case 6 : include 'june.php';
break;
case 7 : include 'july.php';
break;
case 8 : include 'august.php';
break;
case 9 : include 'september.php';
break;
case 10: include 'october.php';
break;
case 11: include 'november.php';
break;
case 12: include 'december.php';
break;
}
?>
And this is working only if I change $month = date(‘n’); to $month = date(‘5’);
But I need the process to be automatic, is this at all possible?
I prefer to use PHP’s require because if there is a problem an error is produced. Also while testing I prefer to use PHP’s die; because it immediately halts execution and displays any messages. Without the PHP die; and depending on the error configuration error messages are mostly likely to be hidden.
is what I suggested - not date(‘M’) and not adding may before the .php
date(‘F’) - will currently return ‘April’ then strtolower converts it to ‘april’ to which the concatenation makes it ‘april.php’. Tomorrow you’d get ‘may.php’;
strtolower(date(‘M’)).‘may.php’ - currently gives ‘aprmay.php’ and tomorrow it will give ‘maymay.php’
I apologise for supplying script which was not tested.
The problem was date('n'); returns a string and not an integer.
A quick solution, which I have tested is to force the string to be an integer:
Update:
$month = date('n'); // "4" == April, "5" = May, etc // string with no leading zero
switch( (int) $month ){
case 1 : include 'january.php'
break;
case 2 : include 'february.php'
break;
...
...
...
} // endswitch(...)