我想在WordPress中列出特定父类别的所有子类别,我是PHP的新手,所以我需要一些帮助,任何帮助都会集会升值,我想要类似下面的代码
<h2>Maine Category 1</h2>
<div class="row">
<div class="col">Subcategory 1</div>
<div class="col">Subcategory 2</div>
</div>
<div class="row">
<div class="col">Subcategory 3</div>
<div class="col">Subcategory 4</div>
</div>
<div class="row">
<div class="col">Subcategory 5</div>
<div class="col">Subcategory 6</div>
</div>
答案 0 :(得分:0)
试试这个 注意: 15是您的父类别ID。
$args = array('child_of' => 15);
$categories = get_categories( $args );
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>';
}
答案 1 :(得分:0)