首页 > 解决方案 > 多种自定义帖子类型博客页面

问题描述

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

我知道我可能错过了一些愚蠢的事情,但我不确定我做错了什么,并希望得到帮助。下面的示例代码:

<?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;
     

标签: phploopswhile-loopcustom-post-type

解决方案


Figured it out, I knew it was something stupidly simple. Changing

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

in post_type POST loop to

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

fixed the problem with it not displaying correctly.


推荐阅读