I use this code to get tags from category.
I want to display in the category page the specific tags. I have 8 categories and this is my code:
<?php if (is_category('10')) { ?>
<?php $args = array(
'categories' => '10'
);
$tags = get_category_tags($args);
$content .= "<ul>";
foreach ($tags as $tag) {
$content .= "<li><a href="$tag->tag_link">$tag->tag_name</a></li>";
}
$content .= "</ul>";
echo $content; ?>
<?php } elseif (is_category('4')) { ?>
<?php $args = array(
'categories' => '4'
);
$tags = get_category_tags($args);
$content .= "<ul>";
foreach ($tags as $tag) {
$content .= "<li><a href="$tag->tag_link">$tag->tag_name</a></li>";
}
$content .= "</ul>";
echo $content; ?>
.....
Do that for each category I thinks is not the best way, any idea?
If you use
get_terms()
, then you can retrieve all terms for a given taxonomy (this includes category as well as post-tag).To get the category on a category archive page, you can use
which will give you an
object
of the currently displayed cat archive page.So the actual term list will be available with something like the following: