繁体   English   中英

仅显示当前类别页面的子类别

[英]Show only child categories of current category page

我很难让孩子进入当前类别页面。 例如,我当前在第4类的页面上。它似乎只是在拉它的兄弟姐妹,而不是孩子。 我不希望那里的兄弟姐妹,只有孩子们。 这是我的代码:

 <?php
 $this_category = get_the_category();
 $child_categories=get_categories( array( 'parent' => $this_category->cat_ID,));
     foreach($child_categories as $category) { 
         $category_url = get_category_link( $category->term_id );
         $category_name = $category->cat_name;
         $category_description = $category->description;
 ?>
 <div class="col3">
     <img src="<?php echo z_taxonomy_image_url($category->term_id, array(365, 165)); ?>">
     <h3><a href="<?php echo $category_url?>"><?php echo $category_name?></a></h3>
     <p><?php echo $category_description?></p>
     <a class="view-more" href="<?php echo $category_url?>">View More</a>
 </div>
 <?php
 }?>

任何帮助将不胜感激。

在意识到我使用了错误的wordpress _get函数后,我发现了这一点。

                $this_category = get_category( $cat );
                $child_categories=get_categories( array( 'child_of' => $this_category->cat_ID,));
                foreach($child_categories as $category) { 
                        $category_url = get_category_link( $category->term_id );
                        $category_name = $category->cat_name;
                        $category_description = $category->description;
                    ?>
                <div class="col3">
                    <img src="<?php echo z_taxonomy_image_url($category->term_id, array(365, 165)); ?>">
                  <h3><a href="<?php echo $category_url?>"><?php echo $category_name?></a></h3>
                  <p><?php echo $category_description?></p>
                  <a class="view-more" href="<?php echo $category_url?>">View More</a>
                </div>
                    <?php
                }?>

暂无
暂无

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

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