【发布时间】:2020-12-05 08:54:05
【问题描述】:
我正在尝试显示自定义分类中的术语和描述列表。
我有以下代码,它按字母顺序返回所有带有指定自定义分类描述的术语。但是,我只想显示最近的五个术语,从最新的开始。
<?php
$terms = get_terms('mytaxonomy');
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
echo '<ul>';
foreach ( $terms as $term ) {
$term = sanitize_term( $term, 'mytaxonomy' );
$term_link = get_term_link( $term, 'mytaxonomy' );
echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a><p>' . $term->description . '</p></li>';
}
echo '</ul>';
}
?>
【问题讨论】:
标签: wordpress wordpress-theming custom-taxonomy