[英]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);
}
?>
這是我網站上列表的圖片:
問題是您沒有設置任何處理程序來提交/處理請求。
我將您重定向到官方文檔示例,在這里您可以找到純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$1 onchange='return this.form.submit()'>";
$select = preg_replace( '#<select([^>]*)>#', $replace, $select );
echo $select;
}
?>
<noscript>
<input type="submit" value="View" />
</noscript>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.