Information from an “urgent need to write down not to forget”category. Ah and to share with “near”, of course. The task is to display a list of tags or tags on the category page (archive, headings) in WordPress, and the tags should only correspond to records from the current category.
In this way, we implement a simple filter on labels or a specialized cloud of labels on the pages of the heading.
Next, the actual code for adding labels to the category page:
1. Added to the file function.php current theme:
$posts = get_posts( array('category' => $cat_id, 'numberposts' => -1) );
$tags = array();
foreach($posts as $post)
$post_tags = get_the_tags($post->ID);
if( !empty($post_tags) )
foreach($post_tags as $tag)
$tags[$tag->term_id] = $tag->name;
2. Display the label list itself. You add to the page template category or column in the desired location on the display. In different themes can be on ways: category.php, archive.php (usually standard).
$cat_id = get_query_var('cat');
$tags = get_tags_in_cat($cat_id);
foreach($tags as $tag_id => $tag_name)
$tags_print = '<a href="' .get_tag_link($tag_id). '">' .$tag_name. '</a>';
echo implode(', ', $tags_print);
Well, all-this code will display on the category page a list of tags with links to their pages separated by commas. After a little “shamanism” with css, I turned out such a nice thing:
How to make – you decide – no restrictions. And so – we have implemented a simple filter for tags entries from the current category of WordPress on their own and without additional plugins. By the way what is the functionality of many plugins is in the pro versions, for demanding money, or most of these plugins require you to create a page in which to insert shortcodes and only litter your blog with extra pages and extra code. And then 5 minutes and everything is ready – and most importantly – all done with their own hands and we know what comes from where and where to be displayed.