wordpress - 使用帖子类别查询类别模板上的帖子
问题描述
我有一个名为“案例研究”的自定义帖子类型,用于案例研究和博客帖子的默认帖子类型(“帖子”)。我有一个名为“product_categories”的自定义分类法,用于博客文章和案例研究文章。
在我的类别模板“taxonomy-product_categories.php”上,我想将“博客”文章摘录与“案例研究”文章摘录分开,但我找不到查询文章存档的方法?
我已经尝试过 is_post_type_archive()、is_archive()、is_category() 和 is_tax(),但它们都没有过滤帖子。
我也尝试过查询帖子,但它只是加载了该帖子类型的所有帖子。
解决方案
如果您使用这样的标准,您应该能够使用 while 循环中的 post 对象来区分帖子类型:
<?php while ($query->have_posts()) {
$query->the_post(); ?>
你可以在你的while循环中这样做:
<div class="left-column">
<?php
if ($post->post_type === 'case-studies') {
// Show your case study excerpts
} else {
// No content found message
}
?>
</div>
<div class="right-column">
<?php
if ($post->post_type === 'post') {
// Show your post excerpts
} else {
// No content found message
}
?>
</div>
推荐阅读
- linux - 使用参数运行 Node_Exporter 服务
- javascript - React:如何让提交按钮和文本标签相互通信?
- bash - 使用 bash 在图形模式下对文件进行排序
- java - java.lang.IllegalArgumentException:比较方法违反了它的一般约定,java.base/java.util.TimSort.mergeCollapse
- powershell - “Powershell Banner Outbound”的含义(Suricata)
- wso2 - WSO2 Identity Server 5.10.0 - 创建现有用户时,IS 管理控制台中未显示错误消息
- c# - 如何将 Microsoft AutoML 文本标签预测与分数匹配?
- rabbitmq - RabbitMQ 在 Fanout Exchange 中添加标头
- android - API <23 的 Android MediaRecorder setMaxDuration 失败
- r - 如何以 OTU 负载为箭头绘制 PCOA 双图