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 have set up a wp_nav_menu in Wordpress. I have 2 parent categories, with 2 sub-categories each, so this produces a nested list.

My current code to call this menu is...

<?php wp_nav_menu( 
        array( 
            'theme_location'    =>  'shop-categories',
            'container'         =>  'nav',
            'container_class'   =>  'shop-cat'
        ) 
    ); ?>

... which outputs this...

(I have simplified the code so you just get an idea of the markup)

<nav class="shop-cat">
  <ul>
    <li>
      <a>Clothing</a>
      <ul>
        <li><a>T-Shirts</a></li>
        <li><a>Tops</a></li>
      </ul>
    </li>
    <li>
      <a>Accessories</a>
      <ul>
        <li><a>Earings</a></li>
        <li><a>Hats</a></li>
      </ul>
    </li>
  </ul>
</nav>  

Now I would like to output this...

<select>
  <optgroup label="Clothing">
    <option value="T-Shirts">T-Shirts</option>
    <option value="Tops">Tops</option>
  </optgroup>
  <optgroup label="Accessories">
    <option value="Earings">Earings</option>
    <option value="Hats">Hats</option>
  </optgroup>
</select>

...is this possible to do dynamically? Or will it be better to do this manually? I have had a look around but couldn't find any help on this.

Any help appreciated.

share|improve this question
1  

1 Answer 1

up vote 1 down vote accepted

Have you checked wp_dropdown_categories function?

It displays or retrieves the HTML dropdown list of categories. I'm unsure of your exact needs but it could be a good starting point.

share|improve this answer
    
Yes that is what I want to do. Just display the categories in a Select menu. I will give this a go then report back, it does seem like a good answer –  Adam May 21 '13 at 9:26
    
Thanks mate, that is what I was after –  Adam May 21 '13 at 20:27

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.