【发布时间】:2022-04-09 01:37:49
【问题描述】:
我目前在 single-resources.php 页面上显示我的帖子的自定义分类术语。但是我需要它链接到分类类别页面而不是页面的链接。
这是我目前拥有的:
<?php
$term_list = wp_get_post_terms($post->ID, 'resourcecategory', array("fields" => "all"));
foreach($term_list as $term_single) {
echo '<a class="icon-hv-link" href="' . esc_url( $term_link ) . '"><i class="icon-left-open-big"></i><span>' . $term_single->name . '</span></a>';
}
?>
我以前这样做确实有效,但是它显示了每个分类术语而不是帖子特定的术语,所以它不起作用:(
<?php $terms = get_terms( 'resourcecategory' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
echo '<a class="icon-hv-link" href="' . esc_url( $term_link ) . '"><i class="icon-left-open-big"></i><span>' . $term->name . '</span></a>';
}
}?>
有人知道以某种方式将两者结合起来吗?
【问题讨论】:
标签: php wordpress taxonomy taxonomy-terms