Build Your Own Business Website header image

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

Part 9 – Use a Select Box in the Theme Options Form

Difficulty Level -

Filed Under Topics -

Listed Under Lesson Subjects -

Applies to -

We’ve created the Genesis Theme Options Form and configured the Front Page Template to use those options but so far it’s not very user-friendly from the end user standpoint.

Add Term List to Make the Form User Friendly

You and I may very well be able to enter the category and tag info in no problem but what would be better would be for the end user to choose the category and choose the term rather than have to figure out the ids. We want the end user to be able to choose from a list of terms and so that’s what we’re going to do next. We’re going to make this a tad more sophisticated.

Replace Text Input Types with Select Input Types

These are no longer going to be text input types, now these are going to be select input types. And that starts off with a select and then we want an id= and a name=. There’s our select and then inside of that we’ve got options.

Each option is one of the things that we can select. Well, this 4 needs to line up with this id or name so we’re going to take this bit here to over there and we’re going to put that both in id and name. So our select is set up but the options are a little trickier.

Set a Value and Selected Statement

I’m going to just copy these and show you how they work. The value is the value that gets returned when the thing is selected and when that option is selected. We need it to be in a lower case like this so that we can test for category or post tag so we’re setting a value exactly the way we want it.

Then in php there is this section thing called selected inside of the option and so what we’re doing is saying selected. If this is selected then the Genesis option gets displayed and then we have the name of the option. In this case it’s ‘category’.

So what we have to do is set a value and then add this selected statement where when it’s selected its value is this and that value gets written to the genesis_get_option. Actually, the value doesn’t get written to genesis_get_option, what’s happening is genesis_get_option is reading the value of this section here. And if the value of that lines up with this, then this is what shows up in the drop down as being selected.

Review the Finished Form

It’s not that complicated but it’s also not that straightforward. The trick is that you’re jumping in and out of HTML, into PHP and you’re adding HTML values using PHP. That’s what’s this selected thing is.

In any case, this is what that looks like when you have a fixed number of options and you know what they are. We know we’re looking at categories and tags. Let’s upload this to the site and now we’re going to have a drop down box now instead of this “Choose a taxonomy” we can choose tags or category.

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
Subscription Options
0 Comments… add one
0 comments… add one

Leave a Comment