Support » Plugins » Current term class when on single custom post

  • Resolved simonwammerfors


    I’m using wp_list_categories in a sidebar (outside the loop) to output a tree of links of all terms of a specific taxonomy. When I click one of the links and go to the archive page of that term the list in my sidebar gets updated with a current-cat class for the current term. What I can’t figure out is how to keep this class in my sidebar list as I’m visiting one of the single posts listed at the term archive page.

    I guess I somehow have to populate the parameter current_category in some dynamic way.I’ve found some solutions to this situation in the formus, but only when displaying actual categories in the list, not terms.

    Any suggestions on how to do this?

Viewing 1 replies (of 1 total)
  • Solved it with this:


      global $post;
      $taxonomy = ‘produktslag’;
      $term_id = 0;
      if(is_singular(‘produkt’)){ // post type is optional.
      $terms = wp_get_post_terms( $post->ID, $taxonomy, array(“fields” => “ids”) );
      $term_id = $terms[0]; //we need only one term id

      wp_list_categories(‘orderby=name&taxonomy=produktslag&title_li=&current_category=’ .$term_id); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Current term class when on single custom post’ is closed to new replies.