wordpress实现分类归档下拉选择框快速导航

WordPress教程 2708

不少企业网站有一个便捷功能,就是在底部会有一个“快速导航”,选择快速导航下拉框里的选项后就会自动跳转到相应的页面,wordpress模板也可以实现这项功能,给分类或月份归档的下拉框显示代码添加一个下拉选择框表单即可实现。

分类目录下拉选择框跳转代码:

1
2
3
4
5
6
<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
	$select = wp_dropdown_categories('show_option_none=快速导航&show_count=0&orderby=name&echo=0&hide_empty=0');
	$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?>
	<noscript><input type="submit" value="View" /></noscript>
</form>

月份归档下拉选择框跳转代码:

1
2
3
4
5
<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>

精品推荐: