我有一个简易数字下载存档页面,显示已发布的下载,但也有未决的下载,但它没有假设。 出于某种原因,wp_count_posts()不会影响循环,我也可以在归档页面中看到待处理的帖子。我无法弄清楚为什么。
<?php
$count_posts = wp_count_posts('download');
$published_posts = $count_posts->publish;
$key = 0;
?>
<?php if (have_posts()) : ?>
<div class="all_product">
<div class="row">
<?php while (have_posts()) : the_post();
if ($key < 12) {
?>
<div class="col-lg-3 col-md-4 col-sm-12 single-download-list">
<?php get_template_part('content-grid', 'download'); ?>
</div>
<?php
}
$key++;
endwhile; ?>
</div>
</div>
<?php else : ?>
答案 0 :(得分:1)
<?php
$args= array(
'post_type' => 'download',
'post_status' => 'publish'
)
$posts = get_posts($args);
$key = 0;
?>
<?php if ($posts) : ?>
<div class="all_product">
<div class="row">
<?php foreach($posts as $post) setup_postdata($post );
if ($key < 12) {
?>
<div class="col-lg-3 col-md-4 col-sm-12 single-download-list">
<?php get_template_part('content-grid', 'download'); ?>
</div>
<?php
}
$key++;
endforeach;
endif;
?>
</div>
</div>
<?php
endif;
wp_reset_postdata();?>
?>
<?php else : ?>