WordPress的投资组合:只显示子类别
问题描述:
我有一个WP网站的投资组合部分。 在投资组合页面上显示项目类别。 我想仅显示id = 63的父类别的子类别。WordPress的投资组合:只显示子类别
这是当前的代码:
<?php $terms = get_the_terms($post->ID , 'portfolio_category', 'string'); ?>
<?php $num_of_terms = count($terms); ?>
<?php if($terms) { ?>
<div class="meta-column">
<strong class="caps"><?php esc_html_e('Artist', 'onioneye'); ?><span class="colon">:</span></strong>
<span>
<?php
$i = 0;
foreach($terms as $term) {
if($i + 1 == $num_of_terms) {
echo esc_html($term -> name);
}
else {
echo esc_html($term -> name . ', ');
}
$i++;
}
?>
</span>
</div>
<?php } ?>
答
你能试试这个:
$args = array('child_of' => 63);
$terms = get_categories($args);
代替这个
:
$terms = get_the_terms($post->ID , 'portfolio_category', 'string');
谢谢,但没有奏效。 –