Im using a archive-cpt.php template page to display all my custom post type posts but now I will be categorizing them in taxonomies. I want to add a dropdown filter navigation that will be populated by the name (and link?) of each taxonomy.
I was wondering if I could use the same template and populate it dinamically for title, description and posts or should I do a taxonomy-cat-cpt.php?
I'd love to just use one page and make it load via ajax or maybe just reload but with the same template. Any thoughts?
Im using a archive-cpt.php template page to display all my custom post type posts but now I will be categorizing them in taxonomies. I want to add a dropdown filter navigation that will be populated by the name (and link?) of each taxonomy.
I was wondering if I could use the same template and populate it dinamically for title, description and posts or should I do a taxonomy-cat-cpt.php?
I'd love to just use one page and make it load via ajax or maybe just reload but with the same template. Any thoughts?
Share Improve this question asked Jun 6, 2019 at 0:01 artist learning to codeartist learning to code 3311 gold badge5 silver badges18 bronze badges1 Answer
Reset to default 1You can create taxonomy-cat-cpt.php
, and inside it just use:
<?php get_template_part( 'archive-cpt' ); ?>
Then they'll both use the same template.
Then inside archive-cpt.php
, if you use the_archive_title()
archive the_archive_description()
it will display the appropriate title and description automatically based on whether you're viewing the taxonomy or post type archive.
Regarding posts, as long as you're using the main query (so just have_posts()
and the_post()
and no new WP_Query()
nonsense), then the appropriate posts should be listed, as long as you're using the correct links.
For anything else that needs to be different, you can check is_tax( 'cat-cpt' )
or is_post_type_archive( 'cpt' )
to conditionally hide or show elements for each one.