如果没有帖子我习惯在其他人之后看到这条消息,我不知道为什么它现在没有显示呢?
代码:
<?php
$args = array( 'post_type' => 'event', 'posts_per_page' => 1, 'post_status' => 'future', 'order' => 'ASC' );
$loop = new WP_Query( $args );
if ( have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="event_preview_title"><?php the_title(); ?></div>
<div class="event_details">
<div class="event_date"><?php the_time('m/d/y'); ?></div>
<div class="event_time"><?php the_time('g:i A'); ?></div>
</div>
<?php the_post_thumbnail( array(65,65) ); ?>
<a class="clickthrough" href="<?php bloginfo('wpurl'); ?>/events"></a>
<?php endwhile; else: ?>
<p>Bluebird Books may be coming soon to a neighborhood near you!<br />
We are currently on hiatus planning our next season's schedule. New tour dates will be posted to this page once confirmed. Meanwhile, inquiries about appearances and programs are welcomed! If you are interested in having Bluebird visit your business, school, or special event, please contact us.</p>
<?php endif; ?>
谢谢!
答案 0 :(得分:4)
WP_Query
,但正在检查错误的帖子if ( have_posts() )
应该是
if ( $loop->have_posts() )
答案 1 :(得分:2)
我不确定当你使用奇怪的if / while语法时会发生什么,但是:
endwhile;
我认为您的endwhile
正在结束while
循环,而;
正在结束if
声明。我建议使用标准{
和}
语法,以便更容易阅读:
<?php
$args = array( 'post_type' => 'event', 'posts_per_page' => 1, 'post_status' => 'future', 'order' => 'ASC' );
$loop = new WP_Query( $args );
if (have_posts()) {
while ( $loop->have_posts() ) {
$loop->the_post();
?>
<div class="event_preview_title"><?php the_title(); ?></div>
<div class="event_details">
<div class="event_date"><?php the_time('m/d/y'); ?></div>
<div class="event_time"><?php the_time('g:i A'); ?></div>
</div>
<?php
the_post_thumbnail( array(65,65) );
?>
<a class="clickthrough" href="<?php bloginfo('wpurl'); ?>/events"></a>
<?php
}
} else {
?>
<p>Bluebird Books may be coming soon to a neighborhood near you!<br />
We are currently on hiatus planning our next season's schedule. New tour dates will be posted to this page once confirmed. Meanwhile, inquiries about appearances and programs are welcomed! If you are interested in having Bluebird visit your business, school, or special event, please contact us.</p>
<?php
}
?>