我很难让孩子们进入当前的类别页面。例如,我目前在第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
}?>
任何帮助将不胜感激。
答案 0 :(得分:0)
在意识到我使用了错误的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
}?>