Menu combo categories in WordPress 2.5.1

Thursday, July 10, 2008

To create a menu / combo (tag select without a submit button and able to position themselves on the category currently displayed, you can use the following code:

HTML:
  1. "event-dropdown" onchange = 'document.location.href=this.options[this.selectedIndex].value;' > <select name = "event-dropdown" onchange ='document.location.href=this.options[this.selectedIndex].value;'>
  2. "" > Seleziona una categoria </option> <option "" value => Select Category </ option>
  3. <? Php
  4. single_cat_title ( '' , false ) ) : "" ) ; $ foo = ((is_category ())? (single_cat_title ('', false)): "");
  5. ) ; $option = '' ; $ categories = get_categories ( 'orderby = name & hierarchical = 0'); $ option ='';
  6. foreach ($ categories as $ cat) (
  7. $cat- > cat_name == $foo)?"selected":"" ).' $ option. = '<option'. (($cat-> cat_name == $ foo)? "selected": ""). ' value = "/ category / '. $ cat-> category_nicename .'">';
  8. $ option .= $ cat-> cat_name;
  9. $ option .= '('. $ cat-> category_count .')';
  10. $ option .= '</ option>';
  11. )
  12. echo $ option;
  13. ?>

The event onchange in tag select eliminates any submit button. Function WordPress is_category() however, you can determine whether we are seeing an "archive" categories, so as to obtain the title / name of the category displayed.

Related Post

Was this article helpful?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

There are no comments for this post

Leave a comment

TAG XHTML PERMISSIONS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre>         // blocco generico [code][/code]       // blocco generico [as][/as]           // Actionscript [css][/css]         // CSS Style Sheet [html][/html]       // HTML [js][/js]           // Javascript [objc][/objc]       // Objective-C [php][/php]         // PHP [sql][/sql]         // SQL