• i have list term on single-services.php

    
          <?php
    
    $all_terms = get_terms( 'services_tax', array( 'hide_empty' => 0,     'childless'  => false,
    'parent' => 0, ) );
    foreach (  $all_terms as $term ) {
      $term_link = get_term_link($term);
      $class = ( is_tax('services_tax', $term->slug) ) ? 'current' : '';
    echo "<div class='acc-tags'>";
    echo "<h6 class='red-text $class'><a href='$term_link'>$term->name</a></h6>";
    echo "<div class='under-text'>";
    echo "<ul class='under-list'>";
    $query = new WP_Query( array(
     'post_status' => 'publish',
     'posts_per_page' => -1,
     'tax_query' => array(
         array(
             'taxonomy' => 'services_tax',
             'field'    => 'slug',
             'terms'    => $term->slug,
             'include_children' => false,
         )
     )
    ));
    
    while ( $query->have_posts() ) {
     $query->the_post();
     ?>
              <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
              <?php  
    } 
    echo "</ul>";
    echo "</div>";
    echo "</div>";
    } 
    
    ?>

    $class is my condition on taxonomy-services.php and this work i adding class if this current term (like menu)
    but i have problem with posts. how i could fix that?
    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Sorry, I don’t follow. What problem with posts do you need to fix?

    Thread Starter poylar

    (@poylar)

    I need check :
    if on post term page add to this term class in term list
    and check only for the first term in the hierarchy
    simple:
    There are terms:
    fruits and vegetables.
    Fruits have notes apples and pears.
    How can I add a class to the name “fruits” if we are on the page apples or pears?
    Now they work for me only if we are on the fruits page, then $ class is added to it
    In short, the essence of the work as with menu items in fact.

    Thread Starter poylar

    (@poylar)

    like is_tax(‘services_tax’)
    but i need something like this:
    is_post_tax(‘services_tax’)

    Moderator bcworkz

    (@bcworkz)

    To determine any term’s top level ancestor, use get_ancestors(). The last term ID in the returned array is the top level term. If the current term already is top level an empty array is returned.

    To determine if a post is assigned a particular term, use get_post_terms(). Pass a “fields” argument to get an array of only term slugs or IDs suitable for use in in_array() to see if any match the current term.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Condition for being inside term post?’ is closed to new replies.