Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

1 Answer

You should use

<?php wp_dropdown_categories(); ?> 

http://codex.wordpress.org/Function_Reference/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
add comment

Your Answer

 
discard

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.