Forums

Create a list of tags based on 1 category (3 posts)

  1. Atticus_Finch12
    Member
    Posted 6 months ago #

    I am trying to create lists of tags based on one category, instead of listing all of them together. I have the code to list all of my tags:

    <?php
    $tags = get_tags();
    $tags_count = count($tags);
    $percolumn = ceil($tags_count / 3);
    for ($i = 0;$i < $tags_count;$i++):
    if ($i < $percolumn):
    $tag_left .= '
    	<li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .'</a></li>
    ' . "\n";
    elseif ($i >= $percolumn && $i < $percolumn*2):
    $tag_mid .= '
    	<li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .'</a></li>
    ' . "\n";
    elseif ($i >= $percolumn*2):
    $tag_right .= '
    	<li><a href="'. get_tag_link($tags[$i]->term_id) . '"rel="tag">' . $tags[$i]->name .'</a></li>
    ' . "\n";
    endif;
    endfor;
    ?>

    What do I need to add to only get tags that are from say cat=1

  2. ChristiNi
    Member
    Posted 6 months ago #

  3. Atticus_Finch12
    Member
    Posted 6 months ago #

    Thanks for the information, but those didn't do exactly what I was looking for. However, for anyone that is interested in generating a list of tags from a specific category, you can find out how to do it here . Below is the code from the stakoverflow page:

    <ul>
           <?php
                        query_posts('category_name=html');
                        if (have_posts()) : while (have_posts()) : the_post();
    
                            if( get_the_tag_list() ){
                                echo $posttags = get_the_tag_list('<li>','</li><li>','</li>');
                            }
    
                        endwhile; endif; 
    
                        wp_reset_query();
                    ?>
    </ul>

Reply

You must log in to post.

About this Topic