多个自定义 Post 类型博客页面

Multiple Custom Post Types Blog Page

我有一个名为 custom_post_type 的促销活动,我正试图在博客页面旁边的 index.php 中正确显示它。当我访问网站时。com/promotions 它会显示所有当前的促销活动。但是,当我访问 website.com/blog 时,它说没有找到两次。 (目前网站上有 2 个博客)。每个 post 类型和循环的查询都存储在它们相应的模板部件文件中。

我知道我可能遗漏了一些愚蠢的东西,但我不确定我做错了什么,希望得到帮助。示例代码如下:

<?PHP 
if ( have_posts() ) :       
     if ( is_home() && ! is_front_page() ) :
     endif; 
     if ( get_post_type( get_the_ID() ) == 'post' ) : ?>
          ...HTML...<?PHP 
          while ( have_posts() ) :
               the_post();
               get_template_part( 'template-parts/content', 'none' );
          endwhile;
          the_posts_navigation(); ?>
          ...HTML...<?PHP
     endif; ?>
     ...HTML...<?PHP
     if ( get_post_type( get_the_ID() ) == 'promotions' ) : ?>
          ...HTML...<?PHP
          while ( have_posts() ) :
               the_post();
               get_template_part( 'template-parts/content', get_post_type() );
          endwhile;
          the_posts_navigation(); ?>
          ...HTML...<?PHP
     endif;
endif;
     

想通了,我知道这很简单。改变

get_template_part( 'template-parts/content', 'none' );

在post_type POST循环到

get_template_part( 'template-parts/content', get_post_type() );

修复了显示不正确的问题。