Wordpress 小部件如何仅显示基于所选父类别的子类别? [英] Wordpress widget how to only display sub-categories based on selected Parent Category?

查看:19
本文介绍了Wordpress 小部件如何仅显示基于所选父类别的子类别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道如何修改现有的类别小部件以仅显示所选父类别中的类别.示例:

I was wondering if anybody know hows to modify the existing category widget to only display the categories within the selected parent category. Example:

如果我的类别结构如下:

If my categories are structured like:

  • 计算机
    • 笔记本电脑
    • 台式机
    • 软件
    • 相机
    • 音频/视频

    如果有人正在查看计算机类别中的帖子,我希望侧栏中的类别小部件仅显示笔记本电脑、台式机和软件..

    If somebody is viewing posts in the Computers category I would like the categories widget in the side bar to only display Laptops, Desktops & Software..

    有没有办法做到这一点?有人熟悉可能会这样做的插件吗?谢谢!

    Is there a way to get this done? Is anybody familiar of a plugin that maybe do that? Thanks!

    推荐答案

    感谢您的帮助.通过这样做,我能够让它工作......

    Thanks for your help. I was able to get it to work by doing this...

    <?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 '<h3>Products</h3>'; 
         echo '<ul>'.$this_category.'</ul>'; 
        }
    }
    ?>
    

    这篇关于Wordpress 小部件如何仅显示基于所选父类别的子类别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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