0

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

<p>
            Select a style from the list
            <?php
            $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>";

   ?>
            </p>

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

1
  • Don't worry, I made it work; like this:
    – Towfiq
    Commented Dec 18, 2010 at 5:33

1 Answer 1

2

You should use

<?php wp_dropdown_categories(); ?> 

http://codex.wordpress.org/Function_Reference/wp_dropdown_categories

2
  • 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
    Commented Dec 18, 2010 at 5:34
  • @Towfiq: Please add you solution as an answer to your question and mark it as the solution.
    – hakre
    Commented Dec 27, 2010 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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