admin管理员组文章数量:1278984
Currently I have this code
$tag_list = get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
and outputs:
<ul>
<li><a href="tag_link">tag_name</a></li>
....
</ul>
How can I change it so it displays like this?
<ul>
<li><a href="tag_link"><span>tag_name</span></a></li>
....
</ul>
Currently I have this code
$tag_list = get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
and outputs:
<ul>
<li><a href="tag_link">tag_name</a></li>
....
</ul>
How can I change it so it displays like this?
<ul>
<li><a href="tag_link"><span>tag_name</span></a></li>
....
</ul>
Share
Improve this question
asked Oct 27, 2011 at 12:37
hamahamahamahama
2134 silver badges11 bronze badges
3 Answers
Reset to default 5So, from the get_the_tag_list()
Codex entry:
- $before
- (string) (optional) Leading text.
- Default: 'Tags: '
- $sep
- (string) (optional) String to separate tags.
- Default: ', '
- $after
- (string) (optional) Trailing text.
- Default: None
Since you're using this example:
get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
...edited to save space...
Modify it as such:
get_the_tag_list( '<ul><li><span>', '</span></li><li><span>', '</span></li></ul>' );
...should get you what you're after.
EDIT
I think you misunderstood my question. The span is supposed to be in the anchor tags. Your method would output
<li><span><a></a></span></li>
Sorry about that; I misread the question.
This gets a bit trickier, but is entirely possible. The get_the_tag_list()
template tag uses get_the_term_list()
, which has a filter for the term links, called term_links-$taxonomy
(which for tags would be, term_links-post_tag
.
So, you could write a filter:
function mytheme_filter_post_tag_term_links( $term_links ) {
$wrapped_term_links = array();
foreach ( $term_links as $term_link ) {
$wrapped_term_links[] = '<span>' . $term_link . '</span>';
}
return $wrapped_term_links;
}
add_filter( 'term_links-post_tag', 'mytheme_filter_post_tag_term_links' );
Note: this will apply to every use of get_the_term_list()
that outputs post tags. Caveat emptor.
you could use a filter function, added to functions.php of your theme:
add_filter('the_tags', 'wp32234_add_span_get_the_tag_list');
function wp32234_add_span_get_the_tag_list($list) {
$list = str_replace('rel="tag">', 'rel="tag"><span>', $list);
$list = str_replace('</a>', '</span></a>', $list);
return $list;
}
I think you're missing the echo
before rendering the tags list:
<?php echo get_the_tag_list('<h3>' . __( ' Tags:', 'theme_name' ) . '</span></h3>'); ?>
Hope this help.
本文标签: tagsHow do I change the output of getthetaglist()
版权声明:本文标题:tags - How do I change the output of get_the_tag_list()? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741300626a2371070.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论