我有以下 PHP 代码,用于输出所有自定义分类值的列表,然后按首字母按字母顺序将它们分组。这工作正常,只是没有输出 URL。有谁能帮忙吗?
<?php
$list = '';
$tags = get_terms( 'film-categories' );
$groups = array();
if( $tags && is_array( $tags ) ) {
foreach( $tags as $tag ) {
$first_letter = strtoupper( $tag->name[0] );
$groups[ $first_letter ][] = $tag;
}
if( !empty( $groups ) ) {
foreach( $groups as $letter => $tags ) {
$list .= '<div class="cat-group"><h3>' . apply_filters( 'the_title', $letter ) . '</h3>';
$list .= '<ul>';
foreach( $tags as $tag ) {
$url = esc_attr( get_tag_link( $tag->term_id ) );
$name = apply_filters( 'the_title', $tag->name );
$list .= '<li><a href="' . $url . '">' . $name . '</a></li>';
}
$list .= '</ul></div>';
}
}
} else $list .= '<p>Sorry, but no tags were found</p>';
echo $list;
?>