Hey all. This could be a long, but rewarding riddle to crack for you coders out there.
I'm currently making a site for my University's radio station and I'm doing it by using some advanced wordpress techniques and modding the hell out of plugins. Just to let you know now, I'm not a computer science student, but I have good self learned knowledge of html/css, but my php is a little sketchy.
Therefore, I've got a bit stuck on one particular feature. I am required to make an 'On Air Now' tab which displays the name and image of the show that is currently on air.
At the moment, I have the following code working well:
<?php
date_default_timezone_set('Europe/London');
$h = date('G'); //set variable $h to the hour of the day
$d = date('w'); //set variable $d to the day of the week.
$year = date('Y'); //set variable $year to the current year
//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.
//Enter show details for each hour within the parses.
// MON SCHEDULE
if ($d == 1 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d == 1 && $h >= 1 && $h < 2) { $showname = ' '; }
else if ($d == 1 && $h >= 2 && $h < 3) { $showname = ' '; }
else if ($d == 1 && $h >= 3 && $h < 4) { $showname = ' '; }
else if ($d == 1 && $h >= 4 && $h < 5) { $showname = ' '; }
else if ($d == 1 && $h >= 5 && $h < 6) { $showname = ' '; }
else if ($d == 1 && $h >= 6 && $h < 7) { $showname = ' '; }
else if ($d == 1 && $h >= 7 && $h < 8) { $showname = ' '; }
else if ($d == 1 && $h >= 8 && $h < 9) { $showname = ' '; }
else if ($d == 1 && $h >= 9 && $h < 10) { $showname = ' '; }
else if ($d == 1 && $h >= 10 && $h < 11) { $showname = ' '; }
else if ($d == 1 && $h >= 11 && $h < 12) { $showname = ' '; }
else if ($d == 1 && $h >= 12 && $h < 13) { $showname = ' '; }
else if ($d == 1 && $h >= 13 && $h < 14) { $showname = ' '; }
else if ($d == 1 && $h >= 14 && $h < 15) { $showname = ' '; }
else if ($d == 1 && $h >= 15 && $h < 16) { $showname = ' '; }
else if ($d == 1 && $h >= 16 && $h < 17) { $showname = ' '; }
else if ($d == 1 && $h >= 17 && $h < 18) { $showname = ' '; }
else if ($d == 1 && $h >= 18 && $h < 19) { $showname = ' '; }
else if ($d == 1 && $h >= 19 && $h < 20) { $showname = ' '; }
else if ($d == 1 && $h >= 20 && $h < 21) { $showname = ' '; }
else if ($d == 1 && $h >= 21 && $h < 22) { $showname = ' '; }
else if ($d == 1 && $h >= 22 && $h < 23) { $showname = ' '; }
else if ($d == 1 && $h >= 23 && $h < 0) { $showname = ' '; }
// TUES SCHEDULE
if ($d == 2 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d == 2 && $h >= 1 && $h < 2) { $showname = ' '; }
.......
// SUN SCHEDULE
if ($d == 0 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d == 0 && $h >= 1 && $h < 2) { $showname = ' '; }
.......
echo ''.$showname.'';
?>
Simple, yes? However, as I am to be leaving Uni at the end of this academic year, I can't count on the fact that the future site maintainers will be able to edit the php, which either way would be a long and boring process. Therefore, I need to automate the script to recognise which show is on air.
All of my show pages are defined by wordpress categories and I'm using a category meta plugin to display extra data.
Therefore, I presume I need to firstly query my show categories (all are a child of category ID 3) by the day and timecode meta that I have defined using the meta plugin:
get_terms_meta($category->term_id, 'dayvalue');
get_terms_meta($category->term_id, 'timecodestart');
get_terms_meta($category->term_id, 'timecodeend');
Then I need to use a function to say IF $dayvalue=1 (for Monday, 2 for Tuesday, 3 for Wednesday etc & 0 for Sunday) and if timecode start is, for example, >12 && <13 ...then it displays its category name and $categoryimage for that particular show.
I'll need to put that same code within the parses for every hour of every day.
That's the logic - I just don't know how to code it and there really isn't much about this area on the net!
edit by admin: no contact information or solicitations for payment are permitted on the forum. Thank you