I'm using the following code to generate tags
<?php if( has_tag() ): ?>
<?php echo '<div id="tagWrapper">'?><p>Tags</p><?php the_tags('<ul class="tags"><li class="tag-body olive">','</li><li>','</li></ul>'); ?><?php echo '</div>' ?>
<?php endif; ?>
It's output is an unordered list with simple <a>
links. I need to apply a class to these links class="tag-body olive
What file is generating these tags I looked in my themes functions.php
Thanks
I'm using the following code to generate tags
<?php if( has_tag() ): ?>
<?php echo '<div id="tagWrapper">'?><p>Tags</p><?php the_tags('<ul class="tags"><li class="tag-body olive">','</li><li>','</li></ul>'); ?><?php echo '</div>' ?>
<?php endif; ?>
It's output is an unordered list with simple <a>
links. I need to apply a class to these links class="tag-body olive
What file is generating these tags I looked in my themes functions.php
Thanks
Share Improve this question asked Jun 30, 2012 at 9:56 AnagioAnagio 9533 gold badges20 silver badges47 bronze badges 2 |2 Answers
Reset to default 4The function get_the_tags();
is probably what you are looking for. The following code displays a list of tags with links to each one and a specific class for each tag:
<?php
$tags = get_the_tags();
$html = '<div class="post_tags">';
foreach ($tags as $tag){
$tag_link = get_tag_link($tag->term_id);
$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
$html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;
?>
Now, using that logic, I've modified your code to do what you want:
<?php if( has_tag() ) { ?>
<div id="tagWrapper">
<p>Tags</p>
<?php
$tags = get_the_tags();
$html = '<ul class="tags">';
foreach ($tags as $tag){
$tag_link = get_tag_link($tag->term_id);
$html .= "<li class="tag-body olive"><a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
$html .= "{$tag->name}</a></li>";
}
$html .= '</ul>';
echo $html;
?>
</div>
<?php } ?>
And the output in case it helps (although untested) should look like this:
<div id="tagWrapper">
<p>Tags</p>
<ul class="tags">
<li class="tag-body olive">
<a href='http://example/tag/technology/' title='Technology Tag' class='technology'>Technology</a>
</li>
<li class="tag-body olive">
<a href='http://example/tag/gadgets/' title='Gadgets Tag' class='gadgets'>Gadgets</a>
</li>
<li class="tag-body olive">
<a href='http://example/tag/mobile/' title='Mobile Tag' class='mobile'>Mobile</a>
</li>
</ul>
</div>
SOURCE: WordPress Codex Function Reference for get_the_tags();
/****post-tag****/
function asr_tags() {
$asrtags = get_the_tags();
foreach($asrtags as $tag){
$string .= '<span class="post-tag"><a class="p-tag" href="'. get_tag_link($tag->term_id) .'">'. $tag->name . '</a></span>' . "\n" ;
}
return $string;
}
add_shortcode('asrtags' , 'asr_tags' );
/*****post-tag*****/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745264259a4619356.html
li
tag – Anagio Commented Jun 30, 2012 at 13:02