I have 3 levels of categories:
Cat 1
- Cat 2
- Cat 3
-- Cat 4
I want to add Parent category name after page title. For example:
<h1>Cat 4</h1>
<p>From Cat3 in Cat 1</p>
But only for third level. Is it possible and what is the better way to do this correct?
I have fond a way to get Cat3, but I still bon't know, how to get previous category name and how to display the message for only third level.
$parent = get_queried_object()->parent;
if( $term = get_term_by( 'id', $parent, 'product_cat' ) ){
echo '<span class="sub-cat">' . $term->name . '</span>';
}
Thanks!
category.php
orarchive.php
- and then add your code. Once you verify you're in the right file, build out the logic that checks the current category to see if it has a parent and grandparent, but not a great-grandparent, and if so outputs that paragraph.