在WordPress侧栏中使用下拉菜单显示分类

WordPress侧边栏的空间是很宝贵的,Wopus中文平台的侧栏想展示的东西很多,就把分类放导航栏了,当然,在侧栏用下拉菜单显示分类也可以节省好多空间,而且效果还很cool。还不会?!跟我来:
其实,Wordpress在设计的时候就为我们考虑这个问题了,我们只需使用函数:

< ?php wp_dropdown_categories(); ?>

该函数缺省用法为:


$defaults = array(‘show_option_all’ => ”, ‘show_option_none’ => ”, ‘orderby’ => ‘ID’,
‘order’ => ‘ASC’, ‘show_last_update’ => 0, ‘show_count’ => 0, ‘hide_empty’ => 1,
‘child_of’ => 0, ‘exclude’ => ”, ‘echo’ => 1, ‘selected’ => 0, ‘hierarchical’ => 0,
‘name’ => ‘cat’, ‘class’ => ‘postform’, ‘depth’ => 0);

给几个使用实例:

  1. Dropdown with Submit Button
  2. < ?php _e('Categories:'); ?>


  3. Dropdown without a Submit Button using JavaScript
  4. < ?php _e('Posts by Category'); ?>

    < ?php wp_dropdown_categories('show_option_none=Select category'); ?>

  5. Dropdown without a Submit Button using JavaScript (2)
  6. < ?php _e('Posts by Category'); ?>

    ]*)>#”, “

够简单吧?!有需要的朋友可以试试!