繁体   English   中英

多种自定义帖子类型博客页面

[英]Multiple Custom Post Types Blog Page

我有一个名为 Promotions 的 custom_post_type,我试图在博客页面旁边的 index.php 中正确显示。 当我 go 访问 website.com/promotions 时,它会显示所有当前的促销活动。 但是,当我 go 访问 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;
     

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

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

在 post_type POST 循环中

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

修复了它无法正确显示的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM