Use the custom post type archive for taxonomies?

Im using a archive-cpt.php template page to display all my custom post type posts but now I will be categorizing them in

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

You 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745425911a4627176.html

相关推荐

  • Use the custom post type archive for taxonomies?

    Im using a archive-cpt.php template page to display all my custom post type posts but now I will be categorizing them in

    4小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信