简体   繁体   English

如何在Wordpress中显示子类别

[英]How to display sub categories in wordpress

I'm trying to display Sub categories on main category page. 我正在尝试在主类别页面上显示子类别。

For example i have a category named as : live tv 例如,我有一个类别,名为: live TV

And it is consist of some sub categories like : sports tv, cartoon tv, entertainment . 它由一些子类别组成,例如: 体育电视,卡通电视,娱乐

I want to display these sub categories with images inside content area of main category. 我想显示这些子类别,并在主要类别的内容区域内显示图像。

I was able to assign images to categories using plugin. 我能够使用插件将图像分配给类别。

I have tried this code in category.php 我已经在category.php中尝试过此代码

<?php
    if (is_category()) {
    $this_category = get_category($cat);
    }
    ?>
    <?php
    if($this_category->category_parent)
    $this_category = wp_list_categories('orderby=id&show_count=0
    &title_li=&use_desc_for_title=1&child_of='.$this_category->category_parent.
    "&echo=0"); else
    $this_category = wp_list_categories('orderby=id&depth=1&show_count=0
    &title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID.
    "&echo=0");
    if ($this_category) { ?> 

<ul>
<?php echo $this_category; ?>

</ul>

<?php } ?>

But that code isn't showing anything on my category page. 但是该代码未在我的类别页面上显示任何内容。

you can also get sub category as: 您还可以获得以下子类别:

<?php global $wpdb;$prefix=$wpdb->prefix;

$subcateogyr_list=$wpdb->get_results("Select * from ".$prefix."term_taxonomy WHERE parent='parent_category_id'");

foreach($subcateogyr_list as $subcat

   echo  $subcat_name=$wpdb->get_var("select name from ".$prefix."wp_terms where term_taxonomy_id='$subcat['term_id']'");

}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM