I think the Template Tag, get_the_tags, might be more appropriate for you.
MichaelH, thanks for your reply.
get_the_tags() is not what I am looking for, as I want to create a list of all tags used, but I don’t want any formating.
I have found this on Trac and have applied the patch, but it still isn’t what I am trying to do
What I was hoping it would do is return the array in the following format:
Array
(
[0] => Array
(
[term_id] => 1
[name] => Slug
[slug] => slug
[count] => 5
)
)
At the moment I’m using get_tags() to get the tags, then using some parts of wp_generate_tag_cloud() to create the list
http://www.roganty.co.uk/blog/tag its still work in progress!
Maybe I could turn it in to some sort of plugin after I’ve finished?
Thanks for your help
You’ve probably figured it out…
<?php
$mytags = get_tags() ;
if ($mytags) {
foreach($mytags as $tag) {
echo '<br /> id ' . $tag->term_id;
echo '<br />name ' . $tag->name;
echo '<br />slug ' . $tag->slug;
echo '<br />count ' . $tag->count;
}
}
?>
I have, thanks MichaelH
Here’s the code I am using:
$tagcloud = get_tags(array('number' => 150, 'orderby' => 'count', 'order' => 'DESC', 'exclude' => '', 'include' => ''));
$counts = $tag_links = $tag_ids = $a = array();
foreach( $tagcloud as $tag ){
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_tag_link($tag->term_id);
$tag_ids[$tag->name] = $tag->term_id;
}
uksort($counts, 'strnatcasecmp');
foreach( $counts as $tag=>$count ){
$tag_id = $tag_ids[$tag];
$tag_link = clean_url($tag_links[$tag]);
$tag = str_replace(' ', ' ', wp_specialchars( $tag ));
$a[] = "<a href=\"$tag_link\" class=\"tag-link-$tag_id\">$tag</a> ($count)"; # title=\"" .attribute_escape( sprintf( __('%d posts'), $count ) ). "\"
}
print "<ul class='wp-tag-cloud'>\r\n<li>";
print join("</li>\r\n<li>", $a);
print "</li>\r\n</ul>\r\n";
Some of it is a direct copy from wp_generate_tag_cloud() in /wordpress/wp-includes/category-template.php
Thanks for your help.
<?php
$mytags = get_tags() ;
if ($mytags) {
foreach((get_the_tags()) as $tag) {
echo ‘ id ‘ . $tag->term_id;
echo ‘name ‘ . $tag->name;
echo ‘slug ‘ . $tag->slug;
echo ‘count ‘ . $tag->count;
}
}
?>
that’s good … but if there s no tag it give Error
it shoud be fixed by some else echo’nothing’ or somthing like that … waiting for a coder
so… are there someone alive ?…
This has already been fixed in the next version of WordPress.
http://trac.ww.wp.xz.cn/ticket/5155
Also, your code above is wrong. It should be this:
<?php
$mytags = get_the_tags() ;
if (!empty($mytags)) {
foreach($mytags as $tag) {
echo ' id ' . $tag->term_id;
echo 'name ' . $tag->name;
echo 'slug ' . $tag->slug;
echo 'count ' . $tag->count;
}
}
?>
get_tags returns *all* the tags.
get_the_tags returns tags for the current post only (and should only be used in The Loop).
Otto42
Think you a lot it works !!