我有一个搜索页面,使用下面的循环显示的新闻项目,我怎么能只显示状态为“未来”的帖子?
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?>>
<div class="news-item" onclick="location.href=\'<?php echo the_permalink(); ?>\'">
<h2><a href="<?php echo the_permalink(); ?>"><?php echo the_time(\'d.m.Y\'); ?> / <?php echo the_title(); ?></a></h2>
<p class="news-page">
<?php if (get_field(\'description\') != "") { ?>
<?php echo the_field(\'description\'); ?>
<?php } else {
$newscontent = get_the_content();
$newscontent_str = strip_tags($newscontent, \'\');
echo substr($newscontent_str,0,250) . "…";
} ?>
</p>
</div>
</div>
最合适的回答,由SO网友:turbonerd 整理而成
类似的方法可能会奏效:
<?php while (have_posts()) : the_post(); ?>
<?php if ( \'future\' === get_post_status( the_ID() ) ) : ?>
<div <?php post_class(); ?>>
<div class="news-item" onclick="location.href=\'<?php echo the_permalink(); ?>\'">
<h2><a href="<?php echo the_permalink(); ?>"><?php echo the_time(\'d.m.Y\'); ?> / <?php echo the_title(); ?></a></h2>
<p class="news-page">
<?php if (get_field(\'description\') != "") { ?>
<?php echo the_field(\'description\'); ?>
<?php } else {
$newscontent = get_the_content();
$newscontent_str = strip_tags($newscontent, \'\');
echo substr($newscontent_str,0,250) . "…";
} ?>
</p>
</div>
</div>
<?php endif; ?>