wordpress创建分类目录下拉表单函数:wp_dropdown_categories

72 阅读1分钟

函数

wp_dropdown_categories( $args );


描述

显示一个目录下拉选择表单元素,函数直接返回html内容。

参数 $args

$args = [
'show_option_all' => '',
'show_option_none' => '',
'option_none_value' => '-1',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1,
'child_of' => 0,
'exclude' => '',
'echo' => 1,
'selected' => 0,
'hierarchical' => 0,
'name' => 'cat',
'id' => '',
'class' => 'postform',
'depth' => 0,
'tab_index' => 0,
'taxonomy' => 'category',
'hide_if_empty' => false,
'value_field' => 'term_id',
];

参数详情

111.png

1112.png

使用例子

带提交按钮的下拉菜单

<li id="categories">
	<h2><?php _e( '分类目录:' ); ?></h2>
	<form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
	    <?php wp_dropdown_categories( 'show_count=1&hierarchical=1' ); ?>
	    <input type="submit" name="submit" value="view" />
	</form>
</li>

欢迎关注我的公众号“xx主题网”,原创技术文章第一时间推送。

文章来源:www.xxzhuti.com/700.html