php - 多种自定义帖子类型博客页面
问题描述
我有一个名为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;
解决方案
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.
推荐阅读
- java - 如何从 json 发送 Java Long 值
- docker - 将 redis 与 docker-compose 一起使用:MISCONF Redis 配置为保存 RDB 快照,但目前无法持久保存在磁盘上
- php - 我收到一个 json 帖子的身份验证错误
- hybris - Hybris 服务器在我重新启动时卡住了
- python - 什么是使用 RNN 进行神经机器翻译的上下文中的投影层?
- manim - 如何将更新程序应用于连接到函数图的线
- django - Django 基于类的视图处理多个查询
- ios - Nativescript 应用程序为 android 构建良好,但不适用于 IOS
- security - 当进程在系统模式/触发器下运行时是否需要检查 isUpdatable() 以通过安全审查过程
- scripting - 在 Win 10 上通过命令提示符运行 J 脚本