G
G
godsplane2020-07-02 13:07:54
WordPress
godsplane, 2020-07-02 13:07:54

The condition that you are in the post terma?

I have a list of terms in single-services.php page

<?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 for the taxonomy-services.php page. It works great there. But I'm having problems with the terms entry page.
The end goal is to add a class to the block if you're on that term's entry page?

More details if you don't understand.

Есть термы:
фрукты и овощи.
У фруктов есть записи яблоки и груши.
Как мне добавить класс к названию "фрукты", если мы находися на странице яблоки или груши?
Сейчас у меня работат только если мы находися на странице фрукты, то к нему добавляется $class
Короче суть работы как с пунктами меню по факту.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question