Wordpress小部件如何只根据选定的父类别显示子类别?

Ash*_*Ash 5 wordpress widget wordpress-plugin

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

如果我的类别结构如下:

  • 电脑
    • 笔记本电脑
    • 台式机
    • 软件
  • 电子产品
    • 相机
    • 音频视频

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

有办法完成这项工作吗?是否有人熟悉插件可能会这样做?谢谢!

Mar*_*rty 5

如何使用这样的东西?在单个页面上,您可以在single.php页面中添加一个新的侧边栏或包含文件...?

即:

<?php if( is_single() ) { include(TEMPLATEPATH.'/newsidebar.php'); } ?>
Run Code Online (Sandbox Code Playgroud)

newsidebar.php

<ul> 
<?php 
 $catsy = get_the_category();
 $myCat = $catsy->cat_ID;
    wp_list_categories('orderby=id&child_of='.$myCat); 
?>
</ul>
Run Code Online (Sandbox Code Playgroud)

这只会显示当前使用类别的类别吗?

即:

如果当前类别是5 //计算机,那么列表中显示的所有内容都是

* Laptops
* Desktops
* Software
Run Code Online (Sandbox Code Playgroud)


Ash*_*Ash 4

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

<?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>'; 
    }
}
?>
Run Code Online (Sandbox Code Playgroud)