问题
I'm trying to add hashtags beside my post tags in Wordpress.
With this code, it looks like : tag1, tag2, tag3
<?php the_tags( '<span class="meta-sep"> | </span><span class="tag-links">' . __( '', 'portfoliopress' ) . '</span>', ', ', '' ); ?>
But I'd like to change it to : #tag1, #tag2, #tag3
I tried to add # into this part
', ', ', '' ); ?>
but it gave me a fatal error. I don't know PHP, but it seems like a simple task. Am I looking in the wrong place?
回答1:
<?php the_tags( '#', ', #', '' ); ?>
EDIT: to add the # to the link text:
if( $tags = get_the_tags() ) {
echo '<span class="meta-sep"> | </span>';
foreach( $tags as $tag ) {
$sep = ( $tag === end( $tags ) ) ? '' : ', ';
echo '<a href="' . get_term_link( $tag, $tag->taxonomy ) . '">#' . $tag->name . '</a>' . $sep;
}
}
来源:https://stackoverflow.com/questions/20705398/add-beside-each-wordpress-tag