这是我的代码,但我只想在当前类别有子类时回显代码。
<?php
$terms = get_terms([
\'taxonomy\' => get_queried_object()->taxonomy,
\'parent\' => get_queried_object_id(),
]);
echo \'<div style="height: 200px; text-transform: uppercase; border:1px solid #666666; padding:10px; overflow-y: scroll;">
<div class="breaker-small">Refine Search</div>\';
foreach ($terms as $term) {
echo \'<p class="filters"><a href="\' . get_term_link($term) . \'">\' . $term->name . \'</a></p>\';
}
echo \'</div>
<br />\';
?>
所以,如果
$terms = get_terms([
\'taxonomy\' => get_queried_object()->taxonomy,
\'parent\' => get_queried_object_id(),
]));
True-然后运行echo。
最合适的回答,由SO网友:CodeMascot 整理而成
您可以像下面这样编写此代码-
<?php
$element = get_queried_object_id();
if (!empty($element)) {
$terms = get_terms([
\'taxonomy\' => $element->taxonomy,
\'parent\' => $element,
]);
echo \'<div style="height: 200px; text-transform: uppercase; border:1px solid #666666; padding:10px; overflow-y: scroll;">
<div class="breaker-small">Refine Search</div>\';
foreach ($terms as $term) {
echo \'<p class="filters"><a href="\' . get_term_link($term) . \'">\' . $term->name . \'</a></p>\';
}
echo \'</div><br />\';
} else {
// Do something
}
?>