December 16, 200916 yr Hi, I'm currently working on a Wordpress site for a radio show and I'm trying to write a PHP script which will display text when the show is on air (Fridays 2-4pm). I've just about got the time part but I don't know how to make it display on specific Fridays as the show is not broadcast every week (e.g. no broadcast next week, Christmas Day!). I don't mind updating the script each year with the new broadcast dates if that helps. Here's what I've got so far: $time = date(H); if ($time <14 ¦¦ $time > 16) { echo "On Air"; } else { echo "Not On Air"; } Thanks in advance, Sam
December 16, 200916 yr Hi Sam, Firstly you need to get the comparison correct. It should be: if (($time >13) && ($time < 16)){ print stuff);} Then using the date() function, do a comparison of dates stored in your database.
December 17, 200916 yr Author Can you give me an example of how I would use the date function to pick specific Fridays?
December 17, 200916 yr You could.. ...have an array of any exclusions you want, and then display "on air" for non-exclusions... <?php $exclusions = array( "25 December 2009" ); //default message to "Not On Air" $message = "Not On Air"; //check for Friday if(date("l") == "Friday") { //then check the time $time = date(H); if ($time >= 14 ¦¦ $time < 16) { //finally make sure today's not excluded if(!in_array(date("d F Y"),$exclusions) { $message = "On Air"; } //end of exclusion check } //end of time check } //end of day check //print out the message echo $message; ?> The formatting is a bit bad because I can't indent on here, but you get the point! Any dates exclusions should be in the form: <2 digit date><space><full month name><space><4 digit year> PS: Your original script will work on any day, my version makes sure that it's Fridays only!
Create an account or sign in to comment