So far in creating the Genesis Child Theme Options we’ve defined our options, given them defaults, set up our sanitization for each of those options and we’ve created a metabox to display those options. Now we have to create the form to do that.
Create a Form with User Selected Choices
Before I show you the full blown form I’m going to show what this tutorial suggests. He’s got a form here, he’s got a title or label and then input type=”text”. It makes it look really simple and unfortunately doesn’t prepare you for the kinds of things you really want to do.
But we’re going to start with this anyway and then we’re just going to make it more complicated as we work our way through this. Ultimately what we’re going to do is let them select from a select box either category or tag. If they select category then they can select from one of the terms and then they can enter a number for the number of posts.
Customize Theme Options Form
So that was a closing “p” tag not an opening one and I don’t want that there but I want to go back into PHP. So we leave PHP, we get to this thing here. Let’s change the name of this. Actually, we’re just going to change this entirely.
It’s not going to be a “p” tag, it’s going to be a label. Actually, we are going to have a “p” tag there. But inside of that “p” tag we’re going to put a label and we’re going to say what the label is for. Then we’ll use this right here as what the label is for ,so label for= and then we’ll paste that there.
The label is for this GENESIS_SETTINGS_FIELD. [box1_taxonomy] and then that is the label so we’ll close that label tag. Then instead of a br what we’ll do is make that a closing label. And, of course, it’s not going to be Favicon URL, it’s going to be Choose a taxonomy.
So we’ve got our label, we’ve got our text input field, input type=”text” name= and again it’s this echo GENESIS_SETTINGS_FIELD with the actual name of the setting. Then value= and in this case, we don’t need esc_attr so we can get rid of that from his example. And value’=genesis_get_option(‘box1_taxonomy’). That is the option that we’re creating so it gets the value that was put there before and shows it here if it exists.
In this case, the size= and we’re going to say 10. So we’ve got our label, we’ve got our input and we’ve got our paragraph tag and you could copy this for each of our pieces. So instead of ‘box1_taxonomy’ it’s ‘box1_term’ and ‘box1_posts_to_show’ and if we don’t do anything else, we’re actually going to have a form that works.
We’ll save that and upload this to our site. Come back over to the dashboard and to Genesis Theme Settings. Here we now have our Front Page Featured Categories. I was fooling around with this on the site today as I was preparing for this session so it stored some of those options but what I could do is I could enter the taxonomy in this way. Call it category. I’ve got “Choose a taxonomy” every time don’t I? I don’t want that. It’s not “Choose a taxonomy” every time, it is “Choose a term” and ” Number of posts to show”. Let’s upload that.