php - 循环浏览有和没有孩子的帖子
问题描述
我有想要循环浏览的这种帖子类型。我必须创建两个不同的部分。顶部在它循环的地方工作。但我想排除持有孩子的父母(#6474)以及该父母中的所有内容,以便在不同的行中循环。
到目前为止我所拥有的。这适用于发布所有帖子。但目前包括所有父母和孩子减去#6474。只是想让这显示那些只是父母的人。
试图弄清楚如何创建另一行,只显示帖子类型中的孩子。
$customersPage_args = array (
'post_type' => array( $global_cat ),
'post_status' => array( 'publish' ),
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'publish_date',
'post__not_in' => array(6474) //excluding the ID holding the children
);
$global_cat_query = new WP_Query( $customers_sort ); ?>
<h3 class="h2 display <?php echo $block[className]; ?>"><?php echo $block_heading; ?></h3>
<div class="card-row">
<div class="card u-pb-0">
<div class="row">
<?php // The Loop
if ( $global_cat_query->have_posts() ) :
while ( $global_cat_query->have_posts() ) : $global_cat_query->the_post(); ?>
<div class="col-md-3 col-sm-4 col-6">
<a href="<?php echo get_permalink(); ?>">
<div class="card card u-mt-0 u-mb-4 align-items-center">
<img src="<?php echo get_the_post_thumbnail_url(); ?>" alt="<?php the_title(); ?>" />
</div>
</a>
</div>
<?php endwhile;
endif;
// Restore original Post Data
wp_reset_postdata(); ?>
</div>
</div>
</div>
<?php endif; ?>
解决方案
如果您只想要顶级项目,则可以使用该post_parent
参数。如果将其设置为0
,它只会找到“父级”(又名“顶级”帖子):
$customersPage_args = array (
'post_type' => array( $global_cat ),
'post_status' => array( 'publish' ),
'posts_per_page' => -1,
'order' => 'ASC',
'orderby' => 'publish_date',
'post__not_in' => array(6474), //excluding the ID holding the children
'post_parent' => 0, // Only get "Top Level" posts
);
推荐阅读
- web-scraping - 从延迟加载的视频中抓取视频链接
- reactjs - 注入一个反应组件作为背景图像
- javascript - 使用reactjs创建表时如何删除连续重复的数据条目
- apache-spark - 如何从列标题中的大 rdd 创建 rdd
- javascript - 反应原生不从父应用调用Android原生方法
- ruby-on-rails - Capybara:Scraper 访问的是加拿大网站而不是美国网站。Indeed.com
- postgresql - 如何在存储过程中编写创建表语句
- angular - Angular 6 服务中未定义 HttpClient 实例
- python - 如何跨所有模板访问模型属性?
- css - 表格列的 CSS 溢出到下一列