• I am using this code for display the Tags inside one category

    <?php
    //get category name
    $catname = get_category(get_query_var(‘cat’))->name;
    //get all tags in this category
    query_posts(“category_name=$catname”);
    if (have_posts()) : while (have_posts()) : the_post();
    $posttags = get_the_tags();
    if ($posttags) {
    foreach($posttags as $tag) {
    //Get Tag ID
    $all_tags_arr[] = $tag -> term_id;
    }
    }
    endwhile; endif;
    //remove duplicates
    $tags_arr = array_unique($all_tags_arr);
    ?>

    I have 2 questions:

    1) How can I display these tags as DROPDOWN instead of Tags Clouds ?

    2) How can I do the same but inverse: I mean display the Categories inside One tag, as DROPDOWN.

    Thanks in advance for your help.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Sorry for the late reply, I’ve been away.

    Unless you want the dropdown to display tag IDs, accumulate the names instead of IDs, then remove the duplicates. After outputting the select HTML tag, loop through each of the unique tag names and output the option tags, values and labels for each tag term. After the loop output the close select tag.

    The inverse is exactly the same logic, but swap tags for categories and vice versa. Get the tag name from the query vars and query posts for all posts with that tag. Loop through the returned posts and accumulate category names. Delete the duplicates and do the select/option thing, this time for each category name.

Viewing 1 replies (of 1 total)
  • The topic ‘Tags and Categories Hack help’ is closed to new replies.