【发布时间】:2020-08-05 19:23:40
【问题描述】:
下面的 sn-p 工作正常,但我已经硬编码了父类别 ID,现在我正在寻找一种方法来摆脱硬编码的 ID。
<div class="row">
<?php
$catsArray = array(176, 175); // This line need to be dynamic and the IDs are parent categories.
$categories = get_terms(
array(
'hide_empty' => false,
'include' => $catsArray, 'orderby' => 'include'
) );
foreach ($categories as $key => $cat) {
$cat_thumb_id = get_term_meta( $cat->term_id, 'thumbnail_id', true );
$term_link = get_category_link( $cat->term_id );
?>
<div class="col-md-6">
<div class="sellers-wrap is-revealing">
<figure>
<img src="<?php echo $cat_img; ?>" alt="" class="img-fluid">
</figure>
<div class="sellers-text">
<p><strong><?php echo $cat->name; ?></strong></p>
</div>
</div>
</div>
<?php } ?>
</div>
【问题讨论】:
标签: php wordpress categories