在每个 wordpress 标签旁边添加“#" [英] Add '#' beside each wordpress tag
本文介绍了在每个 wordpress 标签旁边添加“#"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Wordpress 中的帖子标签旁边添加主题标签.
I'm trying to add hashtags beside my post tags in Wordpress.
用这段代码,它看起来像:tag1, tag2, tag3
With this code, it looks like : tag1, tag2, tag3
<?php the_tags( '<span class="meta-sep"> | </span><span class="tag-links">' . __( '', 'portfoliopress' ) . '</span>', ', ', '' ); ?>
但我想把它改成:#tag1、#tag2、#tag3
But I'd like to change it to : #tag1, #tag2, #tag3
我试图在这部分添加#
', ', ', '' );?>
', ', ', '' ); ?>
但它给了我一个致命的错误.我不懂 PHP,但这似乎是一项简单的任务.我是不是找错地方了?
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?
推荐答案
<?php the_tags( '#', ', #', '' ); ?>
EDIT:将# 添加到链接文本:
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;
}
}
这篇关于在每个 wordpress 标签旁边添加“#"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文