Forums

Get Tags specific to Category (38 posts)

  1. brian7997
    Member
    Posted 2 years ago #

    I have a few requirements: WIDGET!
    1. Localized widget to specific category pages (solved with "Widget Locationizer" plugin)
    2. Show Tags only from posts of specified category

    Is there an easy way to modify the either the simple tag plugin or default tag cloud widget to filter my category?

    Get Tags specific to Category: you can get it by installing Simple Tags plugin and calling st_tag_cloud('category=YOUR_CAT_ID') on your category pages.

    FYI: Also tried this and didn't filter the categories FYI.

  2. shawn67
    Member
    Posted 2 years ago #

    This thread looks similar to what I am looking for. What I need to do is be able to is have default tags for a category so when a post is made, the post is tagged with the category's default tags. I've searched for a plugin to do this but couldn't find anything that sounded like it would auto assign the tags based on the category. Any thoughts on a plugin that can accomplish this or any suggestions of modifications to one of the snippets above would be greatly appreciated.

  3. Josh Stauffer
    Member
    Posted 2 years ago #

    I think an easy way of displaying tags specific to a category without the use of custom DB queries is to use WP_Query and wp_tag_cloud.

    joshstauffer.com/wordpress-get-tags-for-a-specific-category

    Of course you should change category 'blog' to whatever you'd like.

    <?php
    $custom_query = new WP_Query('posts_per_page=-1&category_name=blog');
    if ($custom_query->have_posts()) :
    	while ($custom_query->have_posts()) : $custom_query->the_post();
    		$posttags = get_the_tags();
    		if ($posttags) {
    			foreach($posttags as $tag) {
    				$all_tags[] = $tag->term_id;
    			}
    		}
    	endwhile;
    endif;
    
    $tags_arr = array_unique($all_tags);
    $tags_str = implode(",", $tags_arr);
    
    $args = array(
    'smallest'  => 12,
    'largest'   => 12,
    'unit'      => 'px',
    'number'    => 0,
    'format'    => 'list',
    'include'   => $tags_str
    );
    wp_tag_cloud($args);
    ?>

    I hope someone finds this useful.

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    You above method would make several queries, which would be less efficient then a singular custom query as has been discussed.

  5. Taylor Baybutt
    Member
    Posted 2 years ago #

    I am continuing my custom taxonomy support requests at this thread.
    http://wordpress.org/support/topic/384334?replies=1#post-1465415

    thanks for any and all help. I did get pretty far but the tables do not seem identical to tags.

  6. Taylor Baybutt
    Member
    Posted 2 years ago #

    I have just posted a solution for custom taxonomies at the link above ^

  7. webmatter
    Member
    Posted 2 years ago #

    Thanks to all who recommended the plugin http://wordpress.org/extend/plugins/tdo-tag-fixes/

    It automatically modifies wp_tag_cloud() to only show category specific tags on category or archive pages. This great plugin spared me a LOT of headache :)

  8. unknownclubber
    Member
    Posted 2 years ago #

    Hi !

    I haven't read all discussion but i found something that works fine for me here : http://www.wprecipes.com/get-tags-specific-to-a-particular-category-on-your-wordpress-blog

    I hope it helps

Topic Closed

This topic has been closed to new replies.

About this Topic