单击显示子类别

在我的wordpress网站上,我有一个菜单,显示每个类别的子类别。 我想要做的是默认隐藏子类别,并仅在我单击父类别时显示它们。

我的HTML:

我的functions.php

 function categorias() { $args = array('hide_empty' => FALSE, 'title_li'=> __( '' ), 'show_count'=> 1, 'echo' => 0 ); $links = wp_list_categories($args); $links = str_replace(' (', ' ', $links); $links = str_replace(')', '', $links); echo $links; } 

有任何想法吗? 谢谢。

使用Css隐藏它们: –

 ul.children{ display:none; } 

然后使用jQuery打开它们: –

 jQuery('li.cat-item').on('click',function(){ $('ul.children').hide(); $(this).find('ul.children').show(); }); 

使用此Css如下

   

在Javascript中: