Conditional text for certain categories within taxonomy.php

512 views Asked by At

I am building a Wordpress site using 'Easy Digital Downloads'. The downloads have their own 'categories'. To display an archive of those categories (different from the standard archive.php) I am using a template called taxonomy-download_category.php as specified in their documentation.

This works perfectly and I can set up the category archives as I want. However, I want to display conditional text depending on which category the template is displaying. For example, if the category is 'Test' I want to show some specific text.

I can create a brand new template for the category 'Test' using taxonomy-download_category-test.php but am going to have lots of categories and don't want lots of templates.

I've tried several variations of is_tax is_category but nothing is working.

Here's an example of what I've tried, my guess is I'm not stating the tax/category correctly...

<?php if( is_category( 'download_category-test' ) ) { ?>
TEST
<?php } ?>

I've tried using is_tax using all sorts of combinations cannot get it to work. Here is the result of a dump if this helps anyone to help me find out what I should be conditionally testing for -

object(stdClass)#2868 (10) { ["term_id"]=> int(11) ["name"]=> string(4) "Test" ["slug"]=> string(4) "test" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(11) ["taxonomy"]=> string(17) "download_category" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(1) ["filter"]=> string(3) "raw" }

1

There are 1 answers

4
Pieter Goosen On BEST ANSWER

You should use is_tax() for this

if ( is_tax( 'download_category', 'test' ) ) { 
    echo 'The term page you are viewing is called Test';
}

You can also use get_queried_object(). Just do a var_dump() and inspect the output

var_dump( get_queried_object() );