In my post, Open Source Web Development Software, I discussed some of the open source tools we used in the process of developing a custom WordPress theme for the Better World by Design website. This post dives into the nitty-gritty of some of the theme development involved.
Here’s an example of how we pushed WordPress to the limit – achieving some of the power of Drupal while maintaining the top-notch usability of WordPress. One of the more involved pieces of the theme was a dynamic schedule of conference activities.
Requirements
- The schedule needed to show items across multiple content types (or “custom post types” in WordPress parlance).
- The conference spanned three days, so items needed to be grouped by day, then ordered by start time.
- Content entry should follow the principle of DRY (don’t repeat yourself). Data will appear in various views, but it should only be entered once.
Plugins Used
Charles and Ray Eames famously instructed readers to “innovate as a last resort“. In that spirit, this feature stood on the shoulders of some solid WordPress plugins and innovated only where necessary.
- Custom Post Type UI: Admin UI for creating custom post types and taxonomies.
- Simple Fields: Allows the addition of custom fields such as textareas, checkboxes, radio buttons, drop-downs, or file uploads to specified post types.
Content Setup
Items that appear on the schedule page are comprised of the following custom post types:
- Speakers
- Panels
- Workshops & Tours (they are grouped together because they occurred in the same time slot)
- Events (such as social mixers)
- Schedule Items (opening, closing, breaks, meals)
Each of those custom post types listed above had the following custom fields:
- Day
- Start Time
- Hour
- Minute
- AM / PM
- End Time
- Hour
- Minute
- AM / PM
Approach
The basic approach consisted of lots of array manipulation before some fairly simple output.
//query for all schedule content $schedule_query = new WP_Query(array('posts_per_page' => -1, 'post_type'=>array('speakers','panels','workshops-tours','events','schedule-items'));
while ($schedule_query->have_posts()) : $schedule_query->the_post(); //defining variables for each post $id = get_the_id(); $day = simple_fields_get_post_value(get_the_id(), 'Day', true); $start_am_pm = simple_fields_get_post_value(get_the_id(), 'Start - AM/PM', true); $start_hour = simple_fields_get_post_value(get_the_id(), 'Start - Hour', true); $start_minute = simple_fields_get_post_value(get_the_id(), 'Start - Minute', true); $end_am_pm = simple_fields_get_post_value(get_the_id(), 'End - AM/PM', true); $end_hour = simple_fields_get_post_value(get_the_id(), 'End - Hour', true); $end_minute = simple_fields_get_post_value(get_the_id(), 'End - Minute', true);
// if start hour and end hour are both single-digit values, concatenates a 0 before both start hour and end hour if (($start_hour == 1 || $start_hour == 2 || $start_hour == 3 || $start_hour == 4 || $start_hour == 5 || $start_hour == 6 || $start_hour == 7 || $start_hour == 8 || $start_hour == 9) && ($end_hour == 1 || $end_hour == 2 || $end_hour == 3 || $end_hour == 4 || $end_hour == 5 || $end_hour == 6 || $end_hour == 7 || $end_hour == 8 || $end_hour == 9)){ $full_time = $start_am_pm.'0'.$start_hour.$start_minute.$end_am_pm.'0'.$end_hour.$end_minute; }// if start hour is single-digit value, concatenates a 0 before start hour elseif ($start_hour == 1 || $start_hour == 2 || $start_hour == 3 || $start_hour == 4 || $start_hour == 5 || $start_hour == 6 || $start_hour == 7 || $start_hour == 8 || $start_hour == 9){ $full_time = $start_am_pm.'0'.$start_hour.$start_minute.$end_am_pm.$end_hour.$end_minute; } // if end hour is single-digit value, concatenates a 0 before end hour elseif ($end_hour == 1 || $end_hour == 2 || $end_hour == 3 || $end_hour == 4 || $end_hour == 5 || $end_hour == 6 || $end_hour == 7 || $end_hour == 8 || $end_hour == 9){ $full_time = $start_am_pm.$start_hour.$start_minute.$end_am_pm.'0'.$end_hour.$end_minute; } // otherwise concatenates all time as is else { $full_time = $start_am_pm.$start_hour.$start_minute.$end_am_pm.$end_hour.$end_minute; }
// replaces 12 with 00 for correct ordering by hour $full_time = str_replace('12' , '00' , $full_time);
$counter_friday = 0; $counter_saturday = 0; $counter_sunday = 0;if ($day == 'Friday'){ $friday_arr[$counter_friday] = array('post_type'=>get_post_type(), 'title'=>get_the_title(), 'permalink'=>get_permalink(), 'start_am_pm'=>$start_am_pm, 'start_hour'=>$start_hour, 'start_minute'=>$start_minute, 'end_am_pm'=>$end_am_pm, 'end_hour'=>$end_hour, 'end_minute'=>$end_minute, 'location'=>$location, 'room'=>$room, 'full_time'=>$full_time); $counter_friday++; } elseif($day == 'Saturday'){ $saturday_arr[$counter_saturday] = array('post_type'=>get_post_type(), 'title'=>get_the_title(), 'permalink'=>get_permalink(), 'start_am_pm'=>$start_am_pm, 'start_hour'=>$start_hour, 'start_minute'=>$start_minute, 'end_am_pm'=>$end_am_pm, 'end_hour'=>$end_hour, 'end_minute'=>$end_minute, 'location'=>$location, 'room'=>$room, 'full_time'=>$full_time); $counter_saturday++; } elseif($day == 'Sunday'){ $sunday_arr[$counter_sunday] = array('post_type'=>get_post_type(), 'title'=>get_the_title(), 'permalink'=>get_permalink(), 'start_am_pm'=>$start_am_pm, 'start_hour'=>$start_hour, 'start_minute'=>$start_minute, 'end_am_pm'=>$end_am_pm, 'end_hour'=>$end_hour, 'end_minute'=>$end_minute, 'location'=>$location, 'room'=>$room, 'full_time'=>$full_time); $counter_sunday++; }
Conclusion
Thinking through all the logical implications of a 12-hour clock suddenly makes the 24-hour clock much more appealing. It’s amazing the gymnastics we are hardwired to do subconsciously in our heads.