wp_dropdown_categories 不可点击
wp_dropdown_categories not clickable
所以我做了这个 Php 代码来列出当前类别的子类别。
它甚至会检查该类别是否有子项,如果有,它会列出它们。
但问题是,虽然它在我的网站上看起来还不错。这些链接根本不起作用。当我从列表中选择一个子类别并单击它时,没有任何反应。
<?php
$args = array(
'hierarchical' => 0,
'orderby'=> 'title',
'show_option_none' => 'Subcategories',
'parent' => get_query_var('cat'));
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => true
) );
if($children) {
wp_dropdown_categories($args);
}
?>
这是我网站上列表的图片:
问题是您没有为 submit/process 请求设置任何处理程序。
我会将您重定向到官方文档示例,您可以在其中找到纯粹的 php 或 javascript 解决方案。
https://codex.wordpress.org/Function_Reference/wp_dropdown_categories#Examples
如有需要说明的,欢迎留言。
这是更改后的基础 url 和我的 $args 中添加的行
这会将我发送到 http://www.papercraftplaza.com/category/animals/?cat=bear
<form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/category/'.get_cat_name($cat).'/' ) ); ?>" method="get">
<?php
$args = array(
'cat' => get_query_var('cat'),
'hierarchical' => 0,
'value_field' => 'slug',
'orderby'=> 'title',
'show_option_none' => 'Subcategories',
'echo' => false,
'parent' => get_query_var('cat'));
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => true
) );
if($children) {
$select = wp_dropdown_categories($args);
$replace = "<select onchange='return this.form.submit()'>";
$select = preg_replace( '#<select([^>]*)>#', $replace, $select );
echo $select;
}
?>
<noscript>
<input type="submit" value="View" />
</noscript>
所以我做了这个 Php 代码来列出当前类别的子类别。 它甚至会检查该类别是否有子项,如果有,它会列出它们。
但问题是,虽然它在我的网站上看起来还不错。这些链接根本不起作用。当我从列表中选择一个子类别并单击它时,没有任何反应。
<?php
$args = array(
'hierarchical' => 0,
'orderby'=> 'title',
'show_option_none' => 'Subcategories',
'parent' => get_query_var('cat'));
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => true
) );
if($children) {
wp_dropdown_categories($args);
}
?>
这是我网站上列表的图片:
问题是您没有为 submit/process 请求设置任何处理程序。
我会将您重定向到官方文档示例,您可以在其中找到纯粹的 php 或 javascript 解决方案。
https://codex.wordpress.org/Function_Reference/wp_dropdown_categories#Examples
如有需要说明的,欢迎留言。
这是更改后的基础 url 和我的 $args 中添加的行 这会将我发送到 http://www.papercraftplaza.com/category/animals/?cat=bear
<form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/category/'.get_cat_name($cat).'/' ) ); ?>" method="get">
<?php
$args = array(
'cat' => get_query_var('cat'),
'hierarchical' => 0,
'value_field' => 'slug',
'orderby'=> 'title',
'show_option_none' => 'Subcategories',
'echo' => false,
'parent' => get_query_var('cat'));
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => true
) );
if($children) {
$select = wp_dropdown_categories($args);
$replace = "<select onchange='return this.form.submit()'>";
$select = preg_replace( '#<select([^>]*)>#', $replace, $select );
echo $select;
}
?>
<noscript>
<input type="submit" value="View" />
</noscript>