Can it be written/coded in PHP to display content depending on the date?
For example: I want information about Topic A to display from November 5 to November 12. But leading up to November 5 I want it display Teaser Information A and after November 12 display Ending Message A.
Display certain information depending on the date?
Moderator: General Moderators
- Sofw_Arch_Dev
- Forum Commoner
- Posts: 60
- Joined: Tue Mar 16, 2010 4:06 pm
- Location: San Francisco, California, US
Re: Display certain information depending on the date?
Yes, it is very possible. Since you seem to be new I'll try to suggest simple code that's not very terse:
Code: Select all
HTML to display content above
<?php
// formulate a regular expression to parse the date into separate indexable fields
$regex = "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})";
// get today's date
$date = date( 'Y-m-d' );
/* get the date as separate fields in an array called $regs.
$regs[ 1 ] will be year.
$regs[ 2 ] will be month.
$regs[ 3 ] will be day
*/
ereg( $regex, $date, $regs);
if( $regs[ 2 ] == 11 ) {
// month is november
if( $regs[ 3 ] < 5 ) {
?>
HTML for the teaser
<?php
echo "displaying teaser\n";
}
else if( ( $regs[ 3 ] >= 5 ) && ( $regs[ 3 ] <= 12 ) ) {
?>
information HTML
<?php
echo "displaying info\n";
}
else {
?>
ending HTML
<?php
echo "displaying ending\n";
}
} // if November
?>
HTML to display content below