如何解决如何在短代码中获取指定分类学术语的子项
以下短代码列出了自定义术语类型的子项,如何添加功能以列出指定术语的子项,而不是列出所有术语的子项。 e,g
[categories_shortcode tax-slug="drinks"]
PHP代码
add_shortcode( 'categories_shortcode','categories_list' );
function categories_list() {
ob_start();
$taxonomyName = "categories";
$parent_terms = get_terms( $taxonomyName,array( 'parent' => 0,'orderby' => 'slug','hide_empty' => false ) ); ?>
<ul>
<?php
foreach ( $parent_terms as $pterm ) {
$terms = get_terms( $taxonomyName,array( 'parent' => $pterm->term_id,'hide_empty' => false ) );
foreach ( $terms as $term ) : ?>
<li><a href="<?php get_term_link( $term ) ?>"><?php echo $term->name ?></a></li>
<?php endforeach;
}
?>
</ul>
<?php wp_reset_postdata(); ?>
<?php $categories_list = ob_get_clean();
return $categories_list;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。