在WordPress中使用下拉菜单方式显示文章存档和文章分类
通常在wordpress中,我们会以列表的方式显示文章存档和文章分类,但是如果分类比较多的话,列表的方式往往太占用空间,导致侧边栏过于冗长。如果能够以下拉菜单的方式显示文章存档和分类的话,就能节省不少的空间。如何实现呢?很简单。
下面的代码能够将按月归档的文章存档以下拉菜单的方式显示出来,只要将其放入到侧边栏就可以了:
1 2 3 | <select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'> <option value=\"\"><?php echo attribute_escape(__('查看月份归档')); ?></option> <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select> |
1 2 3 4 | <form action="<?php bloginfo('url'); ?>/" method="get"> <?php $select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0'); $select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?> <noscript><input type="submit" value="View" /></noscript> </form> |
   

最好能附上效果图。