0
votes

I have a custom Taxonomy. The lists of terms in the taxonomy will be dynamically created.

I have a custom template for Taxonomy as taxonomy-{custom-template}.php, but I do not want to use the same template for the terms page.

I will not be able to create template for terms upfront as taxonomy-{custom-template}-{term}.php as the terms are created dynamically.

Is there any option to exclude or have a generic template for the terms?

1

1 Answers

1
votes

I'd use is_tax() in your taxonomy-{custom-template}.php to determine whether you are displaying the archive page or the terms page, and them include the relevant code in template parts.

  1. Create 2 new template parts in your template parts folder - lets say its called partials

    • One is for your taxonomy archive page e.g. tax_archive_content.php. Copy the archive-specific code from taxonomy-{custom-template}.php into it.
    • The other is for your terms page - e.g. tax_terms_content.php. Put your new code for handling the terms in here.
  2. Add the following to your taxonomy-{custom-template}.php

(This will replace the archive-specific code that you moved to tax_archive_content.php)

if (is_tax())
    get_template_part('partial/tax_archive_content'); 
else
    get_template_part('partial/tax_terms_content'); 

References for is_tax: