我找到了有关如何在每个标记here中添加#的教程,但我不知道如何将其应用到此代码中。
如何在此代码中添加#?
<?php
if ( get_the_term_list( $post->ID, APP_TAX_TAG ) )
echo get_the_term_list( $post->ID, APP_TAX_TAG, '', '', '' );
else
_e( 'No Tags', APP_TD );
?>
答案 0 :(得分:0)
您可以使用get_the_terms
<?php
$terms = get_the_terms($post->ID, APP_TAX_TAG);
$prefix = "#";
if ( $terms && ! is_wp_error($terms) ) {
$tag_links = array();
foreach ( $terms as $term ) {
$href = get_term_link($term, APP_TAX_TAG);
$tag_links[] = '<a href="' . $href . '">' . $prefix . $term->name . '</a>';
}
echo join(", ", $tag_links);
} else {
_e( 'No Tags', APP_TD );
}
?>
答案 1 :(得分:0)
将#添加到链接文本:
<?php
if ( get_the_term_list( $post->ID, APP_TAX_TAG ) )
$tagsString = get_the_term_list( $post->ID, APP_TAX_TAG, '', '', '' );
$tagsString = preg_replace("#href=\"([^\"])\"#","#href=\"$1\#\"#",$tagsString);
echo $tagsString;
else
_e( 'No Tags', APP_TD );
?>
应该正常工作;)