WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am tyring to add a category drop down list to my theme options page. I am try it this way:

            Select a style from the list
            $amp_categories_obj = get_categories('hide_empty=0');
   $amp_categories = array();
   foreach ($amp_categories_obj as $amp_cat) {
   $amp_categories[$amp_cat->cat_ID] = $amp_cat->category_nicename;
   $categories_tmp = array_unshift($amp_categories, "Select a category:"); 

   echo "<select name='amp_options[amp_cat]'>";
   foreach ($amp_categories_obj as $amp_cat) {
    $selected = ($options['amp_cat']==$amp_cat) ? 'selected="selected"' : '';
    echo "<option value='$amp_cat' $selected>$amp_cat</option>";
   echo "</select>";


I am not much of a PHP coder by the way. Any help would be appreciated.

share|improve this question
Don't worry, I made it work; like this: – Towfiq Dec 18 '10 at 5:33

You should use

<?php wp_dropdown_categories(); ?> 


share|improve this answer
I amde it work: <p> Select a category for your slider from the list <?php $categories= get_categories(); echo "<select name='amp_options[amp_cat]'>"; foreach ($categories as $cat) { $selected = ($cat->cat_name==$options['amp_cat']) ? 'selected="selected"' : ''; echo "<option value='$cat->cat_name' $selected>$cat->name</option>"; } echo "</select>"; ?> </p> – Towfiq Dec 18 '10 at 5:34
@Towfiq: Please add you solution as an answer to your question and mark it as the solution. – hakre Dec 27 '10 at 17:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.