• Resolved rogersabboes

    (@rogersabboes)


    Since wp 3.0 it is possible to display all tags of a specific custom taxonomy using the wp_list_categories(‘taxonomy=my_taxonomy’) – template tag. This works just fine.
    What I am wondering about is if it is possible to display not just all the tags which are used in all of your posts but only those which are used in a specific archive listing.
    I try to make it clear by giving an example:
    Lets say I got two custom taxonomies for my posts. The first is for instance ‘length’ with the tags ‘long’, ‘medium’ and ‘short’; the second is ‘relevance’ with the tags ‘high’, ‘little’ and ‘no’. In each post both taxonomies are added. So one post is tagged ‘long‘ and ‘no‘, another ‘medium’ and ‘high’ and so on.
    Using the wp_list_categories-template tag for both taxonomies on the wp-theme will bring up a list of all the used tags from all the posts. This is fine on the indexpage where all posts are listed. But when it comes that I switch to an archive page (f.i. ‘?length=long’) I would like the listing to be modified that only those tags show up which are assigned to those posts listed in this specific archive.
    Lets say I’m in the archive ‘?length=long’ and none of the listed posts is tagged with ‘relevance=high’. If this is the case the tag ‘high’ is supposed to disappear from the wp_list_categories(‘taxonomy=relevance’)-generated list.

    I guess this thing could be done by changing the query the wp_list_categories-templatetag is doing from global posts to the current query string. As far as I know there is no parameter for setting the querysource in the templatetag. Any ideas would be great. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter rogersabboes

    (@rogersabboes)

    Ok I found a solution doing the trick by modifying a function by MichaelH (http://wordpress.org/support/topic/327333?replies=34).

    $cat_array = array();
     foreach($posts as $post) {
      foreach(get_the_category($post->ID) as $category) {
        $cat_array[$category->term_id] =  $category->term_id;
      }
    }
    $cat_ids = implode(',', $cat_array);
    wp_list_categories('include='.$cat_ids.'&title_li=Categories in the current loop');

    This function shows a list of all categories included in those posts which are currently shown within the loop. When I put it f.i. in my sidebar i can see all the categories from my current query, no matter if I’m on an archive-page, a query-page or on the index-page.

    This function works only for categories. How do I change it that it also lists custom taxonomy-tags, and probably also ‘Tag-tags’ and custom field-values which are currently shown in posts from the loop?

    Another problem I have with this function is that the list ignores categories which are not listed on the first page. For example when I have an archive-page with 15 posts and the first ten are shown at ?cat=22 and the remaining 5 on ?cat=22&paged=2, I will get 2 different results in the category list, including only those categories which are on the specific page. Is there an option to get always the same list, no matter if the posts are on more than one page?
    Thanks a lot!

    Thread Starter rogersabboes

    (@rogersabboes)

    This issue has been resolved here: http://wordpress.org/support/topic/423280?replies=8

    I am trying to do the same thing myself. On the other page it is just an example for displaying categories. Could you share the code that works for listing custom taxonomies?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display only assigned tags of custom taxonomies in archive’ is closed to new replies.