16 Dec Adding a Dropdown Category List to a WordPress Options Panel
I’ve been working on integrating a jQuery slide show into a new theme I’ve been working on. Under the options panel, I have it set to enable and disable the slide show on the front page using simple radio buttons.
I also wanted to allow the user to select which category should be displayed using a select option. I originally wanted to use the WP’s drop down list function, but I just couldn’t get it to load selected value.
I’m sure there is a more efficient way of doing it, but this gets the job done.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <!-- Dropdown Slideshow Category--> <select name='slideshowCat' id='cat'> <option value=""> <?php echo get_cat_name(get_option('slideshowCat')); ?> </option> <option value="all">All</option> <?php $categories = get_categories(''); foreach ($categories as $category) { $option = '<option name="'.$category->cat_ID.'" value="'.$category->cat_ID.'">'; $option .= $category->cat_name; $option .= '</option>'; echo $option; } ?> </select> |
Then you just have to add in_category in your loop to call that category:
1 2 3 4 5 6 | if (have_posts() ) : while(have_posts() ) : the_post(); if(in_category(get_option('slideshowCat'))) { //Pull Posts from Selected Category } else { } |
Sorry, the comment form is closed at this time.