[英]Show Children Categories Only When Parent is Selected (Wordpress/Thesis Theme)
I am trying to create a category based navigation that is dependant on the parent selected. 我正在尝试创建一个基于类别的导航,该导航取决于所选的父项。
For example, I would like to show sub-categories ONLY when the parent is selected and ONLY show the sub categories. 例如,我只想在选择父级时显示子类别,而仅显示子类别。 I have tried a million things and no dice.
我已经尝试了100万件事,没有骰子。
Just to be thorough here is my example: 为了更全面,这是我的示例:
Parent A Parent B Sub-Cat of Parent B Sub-Cat-2 of Parent B Sub-Cat-3 of Parent B 父母A父母B父母B父母的B子猫
At first only Parent A and Parent B are shown. 首先,仅显示父母A和父母B。 If I click Parent B all I will see is the 3 sub categories of Parent B and nothing else.
如果单击“父级B”,我将看到的是“父级B”的3个子类别,仅此而已。
It's basically just conditional navigation with categories. 基本上,这只是带有类别的条件导航。 I have done this before with Pages but categories are proving themselves to be a bitch for me.
我以前在Pages上做到过这一点,但类别证明自己对我来说是个bit子。 Any help would be greatly appreciated.
任何帮助将不胜感激。
Have you tried get_categories 您是否尝试过get_categories
$parent_cat_id = 'your parent category id'; $ parent_cat_id ='您的父类别ID';
$args = array(
'type' => 'post',
'child_of' => $parent_cat_id,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' =>'' ,
'number' =>'',
'taxonomy' => 'category',
'pad_counts' => false );
$categories = get_categories($args);
echo "<pre>";
print_r($categories);
echo "<pre>";
I actually blogged about this a while ago :) Hope this helps :) 我前一段时间实际上在博客上写了:)希望对您有所帮助:)
http://www.themer.me/blog/wordpress/33/how-to-display-sub-categories-depending-on-what-category-youre-in http://www.themer.me/blog/wordpress/33/how-to-display-sub-categories-depending-on-what-category-youre-in
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.