仅显示wordpress子类别 [英] Show wordpress subcategories only

查看:68
本文介绍了仅显示wordpress子类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有7个类别(父母),每个类别都有15个子类别.

I have 7 Categories (parents), and every category has 15 sub-categories.

当我选择某个类别(父级)时,我只想显示该特定父类别(父级)的子类别(子级).

When I select some category (parent), I want to display only sub-categories (children) of that particular parent category (parent).

点击子类别(子类别)后,它应该仅显示其帖子.

After I click on sub-category (child) then it should display its posts only.

我有一个fron_page.phpcategory.php.

如何编写此代码以首先分别显示子类别,然后将该子类别分别发布到用户想要查看的新文件中.

How can I write this to first show sub-categories separately, then post of that sub-category separately in new file, which user want to see.

推荐答案

此代码应为您提供帮助:

This code should help you:

<ul> 
<?php 
 $cats = get_the_category();
 $mycat = $cats->cat_ID;
    wp_list_categories('orderby=id&child_of='.$mycat); 
?>
</ul>

OR

<?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>'; 
    }
}
?>

请让我知道.

祝你好运! :)

这篇关于仅显示wordpress子类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆