我有 7 个类别(父类别),每个类别有 15 个子类别。
当我选择某个类别(父类别)时,我只想显示该特定父类别(父类别)的子类别(子类别)。
点击子类别(子)后,它应该只显示其帖子。
我有一个 fron_page.php
和 category.php
。
如何编写此代码以首先单独显示子类别,然后将该子类别单独发布到用户想要查看的新文件中。
最佳答案
这段代码应该可以帮助你:
<ul>
<?php
$cats = get_the_category();
$mycat = $cats->cat_ID;
wp_list_categories('orderby=id&child_of='.$mycat);
?>
</ul>
或者
<?php
if (is_category()) {
$cat = get_query_var('cat');
$this_category = get_category($cat);
$this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if($this_category !='<li>No categories</li>')
{
echo '<ul>'.$this_category.'</ul>';
}
}
?>
请告诉我。
祝你好运! :)
关于php - 仅显示 WordPress 子类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11163261/