最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Use the custom post type archive for taxonomies?

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论