How to Make a Radio Station Schedule Using WordPress

Often enough, many radio stations are built using WordPress, but many don't harvest the true potential to create a true online radio station. This tutorial will demonstrate how you can turn a radio website into a fully functional radio station DJ listing with a nifty radio schedule for featured shows.


Introduction

For our online radio website, we will feature some DJ's/hosts that play on the air. We will create a custom post type for them, where we can add a picture, biography and other useful information. We will also create a show schedule using the WordPress custom post type again. Mixed with some custom metaboxes, we're going to make the show administration simple to manage.


Step 1 Creating DJ/Host Custom Post Type

To avoid files cluttered with code, we'll separate our snippets and by using the PHP function include, we'll include them to our file. Open your functions.php file, located in your current theme folder and add the following snippet:

Once complete, create a new file called schedule.php, then we add our functions to register our new post type.

For more information on custom post types, try this page custom post type

Adding Post Thumbnails

For this tutorial, we will be using formatted images for the schedule. Therefore, we're going to add the WordPress post thumbnail functionality.

Notice that we've added the function add_image_size and some parameters. We'll be using the post thumbnail size of 260x160 for our end result.


Step 2 Creating Schedule Custom Post Type

Just like the previous step, we're going to create a next post type using the same method and simply changing some names and variables.


Step 3 Adding Custom Meta Boxes

This tutorial won't explain every aspect of creating custom metaboxes, but we'll highlight the most significant. With that said, we'll begin by calling two add_action hooks for our metaboxes.

In you're interested in learning more about custom meta boxes. This is a great read: How to Create Custom WordPress Write/Meta Boxes

Add the Meta-Boxes

The function rschedule_box which was previously mentioned in the hook, will register a group of metaboxes to our post edit screen. We will use these metaboxes on our Schedule Edit page.

Creating a DJ Select List

In this step, we create a function that will generate a select list on our screen. This list will display all the DJs/Hosts added to our custom post type, that we created in Step 1. This function will query the post type and return the items as an array, then we will loop though the array and mix it with some HTML. This way, we can reference the DJ post ID, which we will need in generating our output later.

Creating Time Slots

The next function is our function that will display the days of the week and options to choose the time when the show will be live. In order for us to get the days of the week, we'll create an array.

Now that's done, let's create our time slot function. Add the following code to your file.

As you will notice we referenced our array of days by using global $days. We could have placed it inside of the function but we will be referencing it occasionally, so we'll leave it on the outside. Also, take a look at how the array of days is used, we have chosen to loop some select fields using the days, so we should have several select fields for the 7 days of the week. The variables $selected_start and $selected_end use the WordPress function get_post_meta, in order to get the currently selected value for our list. We are also strategically using the key of our array in our list to name our form field, label and get our selected value. When PHP interprets the field name, it will look similar to this schdule_dj-start-sun where sun will be changed according to the current day in the loop. This will be quite useful to us in other parts of the tutorial. Lastly, you will realise that we've referenced the function schedule_time_select, that we have not created as yet. Let's create that function now.

This function will generate the options for our select list. Each option will be incremented by 15 minutes and is based on the the 24 hour system. For the first option, we set a value of 0 for the days that we wish to neglect. Within the loop, there is a small if statement that checks the value sent from our radio time slot function to determine if the option should be set to selected.


Step 3 Saving the Meta Boxes

Finally, it's time to save all of our metabox information. WordPress has a very simple and straight forward way of saving these options but we're going to make it more dynamic. Add the following snippet to your file.

Once again, you see the usefulness of our global days variable. In this function, we loop through each day and we save our options from our select field by changing the name as the days loops through.


Step 3 Saving the Meta Boxes

Wow! If you're still with me, let's put all these codes to work, shall we? Ok, great! The snippet below demonstrates how we're going to loop through each schedule that we created and place in divs. Add that bit of code and let's break it down.

Firstly, we make a loop for our custom post type dj_schedule, create a div and list the title. While inside the div, we fetch the DJ ID we added in the admin using the get_post_meta function. Then we use that same ID and call the WordPress function get_post for the values of that post and assign them to a variable which we then use to get the DJ's name and photo.

Getting the Time Slots

Directly below our DJ, we have our day loop which loops through each day while making a check to see if any start time exists for that day. If they do exist, then we output the start and end time into a div.

Adding Our Schedule to a Page

We can do many things to add the schedule to a page, but for this tutorial, we will simply use a shortcode. So, with just one line of code, we will create a short code that we can call add on any page and voila! We have a working radio schedule!


Conclusion

This is the first phase of adding more great features to your WP radio website. I have chosen some simple styling for the layout, you can add these styles to your style.css file. In another tutorial, I will explain how to create a nice live stream pop-up with current show, DJ and radio player.


Your feedback is much appreciated. Let me know what you think in the comments below. Happy coding!

Tags:

Comments

Related Articles