php - 适用于所有子类别的 WP 一个模板
问题描述
我有一个父类别“报告”和三个子类别“每日”、“每周”和“每月”。标识如下:
- 报告 ID 4
-
- 每日 ID 5
-
- 每周 ID 6
-
- 每月 ID 7
我想创建一个查询以在单个模板上使用,该模板仅显示来自相同子类别的帖子,并在创建新子类别时工作。现在我已经为每个子类别创建了一个页面并使用相同的模板。但是,我只能让它显示来自父级的帖子,因此它列出了每个子类别的帖子。
<?php
$args = array(
'post_status' => 'publish',
'post_type' => 'post',
'cat' => 4,
// 'category__in' => array(8,9,10,11),
'nopaging' => false,
'posts_per_page' => '10',
'ignore_sticky_posts' => 0,
'order' => 'DESC',
'orderby' => 'date',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post(); ?>
<div class="excerpt">
<h2 class="f-bold f-size28 f-l-height32 c-red">
<a class="f-bold f-size28 f-l-height32 c-red" href="<?php the_permalink(); ?>" title="View Full Post">
<?php the_title(); ?>
</a>
</h2>
</div>
<? }
} else {
echo('no posts at this time');
}
wp_reset_postdata();
?>
如何从页面动态获取子类别的 ID 并仅显示基于该 ID 的帖子?
解决方案
推荐阅读
- c# - 具有多个 OIDC 身份验证配置的 OWIN
- youtube-api - 为用户的 Youtube 直播视频添加叠加层的网络应用程序架构?
- tcp - 我的路由器在端口 111 上进行活动是否正常?
- r - R如何匹配和提取字符串中不同长度的字符字母
- python - 当线段有序但线段的方向是随机的时,有效地对线段列表进行排序
- http - HTTP 状态 404 - 未找到解决方案
- json - 使用 Python 从目录运行和读取
- python - 使用 django-simple-history 和 django-queryable-properties 在 Django 查询集中添加历史字段值
- python - Python - 使用 cx_Freeze 构建二进制文件时,代码保存在哪里?
- python - 检测 Jupyter notebook 时 tqdm 失败