У меня есть этот код для отображения пользовательского текста в категориях, которые я выбираю.
<?php if (is_product_category('furnitures')) : ?> <p>This is the text to describe category A</p> <?php elseif (is_product_category('kitchen')) : ?> <p>This is the text to describe category B</p> <?php else : ?> <p>This is some generic text to describe all other category pages, I could be left blank</p> <?php endif; ?>
Как я могу сделать текст также отображаемым в подкатегориях каждого родителя. В приведенном выше коде есть «мебель» и «кухня» родителя и некоторые подкатегории.
Благодаря!
попробуй это
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); // current term $parent_slug = ''; // default slug param if( $term->parent ){ // if current term has parent then get it's slug $parent = get_term( $term->parent, get_query_var('taxonomy') ); // term's parent $parent_slug = $parent->slug; // slug of parent term } // check current term has product_cat taxonomy $is_product_category = '' === $parent_slug ? 0: is_product_category($term->slug); if ( is_product_category('furnitures') || ( $is_product_category && 'furnitures' === $parent_slug) ) : ?> <p>This is the text to describe category A</p> <?php elseif (is_product_category('kitchen') || ( $is_product_category && 'kitchen' === $parent_slug) ) : ?> <p>This is the text to describe category B</p> <?php else : ?> <p>This is some generic text to describe all other category pages, I could be left blank</p> <?php endif; ?>