所以我想知道我的代码有什么问题,因为我的代码是这样的。我试图循环我的类别,并显示在不同的卡片。我的循环是正确的,我的所有类别都列出了,但我正在挣扎的是让他们在不同的卡-现在他们是在同一张卡。这是我的密码
<section class="py-5">
<div class="container">
<div class="row">
<?php $terms = get_terms( 'deko_category' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<div class="col-md-4">';
foreach ( $terms as $term ) {
echo '<div style="padding: 30px 45px; background-color: #fff; box-shadow:
5px 5px 10px 0 rgb(0 0 0 / 5%);">' . $term->name . '</div>';
}
echo '</div>';
}
?>
</div>
</div>
</section>
发布于 2022-03-18 11:18:13
类别名称:$category->name
或子类别名称:$subcategory->name
// set taxonomies
$taxonomies = get_terms( array(
'taxonomy' => 'taxonomy_name',
'hide_empty' => false
) );
// if not empty.
if ( !empty($taxonomies) ) :
foreach( $taxonomies as $category ) {
// is not parent .
if( $category->parent == 0 ) {
foreach( $taxonomies as $subcategory ) {
if($subcategory->parent == $category->term_id) {
echo '<div style="padding: 30px 45px; background-color: #fff; box-shadow:
5px 5px 10px 0 rgb(0 0 0 / 5%);">' . $subcategory->name->name . '</div>';
}
}
}
}
endif;
https://stackoverflow.com/questions/71526111
复制相似问题