• Posted: 2011-07-20
  • Author: Marketizingco
  • Tags:

Pull in the tags related to a category

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
<?php
$project_query = query_posts('category_name=Real estate marketing');
while (have_posts()) : the_post();
    $posttags = get_the_tags();
    if ($posttags) {
        foreach($posttags as $tag) {
            $all_tags_arr[] = $tag -> name; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
        }
    }
endwhile;

$tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES
foreach( $tags_arr as $tag ):
    $el = get_term_by('name', $tag, 'post_tag');
    $arr[] = '"tag-'.$el->slug.'"';
?>
&lt;span>&lt;a href="<?php echo bloginfo('url'); ?>/tag/<?php echo $el->slug; ?>" id="taglink-tag-<?php echo $el->slug; ?>" rel="tag-<?php echo $el->slug; ?>"><?php echo $el->name; ?>&lt;/a> &lt;span class="slash">, &lt;/span>&lt;/span>
<?php endforeach; ?>

Instructions:

This is a way to show all tags related to a category, without returning them in a list. This is a great way of adding more SEO, and kill some bounce rate.

Just make sure you change the name of your category where the category_name= starts. Use spaces if your category is named using more than one word.

Put this code where you want the tags to be displayed.


Share this snippet

If you like this snippet, share it with friends!