Hi,
I'm trying to get the tags for the current post outside the loop (for usage in a widget). I can't find any way to do it and would appreciate any help i can get.
Hi,
I'm trying to get the tags for the current post outside the loop (for usage in a widget). I can't find any way to do it and would appreciate any help i can get.
I'm looking for the exactly same thing. No luck so far :( Any ideas?
Here's one way to do it:
http://www.jek2k.com/wp/index.php/2006/10/30/wordpress-displaying-content-outside-the-loop/
And another:
http://codex.wordpress.org/Template_Tags/get_posts
To echo a list of tags from a particular post outside the Loop, you can set $post global, then do a foreach loop to echo the tags as normal.
For example, I use this loop to display post tags as meta keywords in my header if the page is a single post page.
<?php
global $post;
foreach(get_the_tags($post->ID) as $tag) {
echo $tag->name . ', ';
}
?>Cool stuff.
This is a bit of code I have been working on. In this example the rtrim function removes the last comma of the last word in the list:
<?php
$posttags = get_the_tags();
foreach((array)$posttags as $tag) {
$show_tags .= $tag->name . ',';
}{
$rel_art .= rtrim($show_tags , ',');{
}
print $rel_art;
}
?>
Based on the examples shown here:
http://www.nathanrice.net/blog/ultimate-guide-to-wordpress-seo-meta-keywords/
http://phphelper.wordpress.com/php-rtrim-function/
This topic has been closed to new replies.