Php 自定义查询上的Wordpress else语句
我有一个自定义查询,我想知道如何添加if语句,这样,如果没有用于此查询的帖子,就会显示一条简单的消息 我的问题是:Php 自定义查询上的Wordpress else语句,php,wordpress,Php,Wordpress,我有一个自定义查询,我想知道如何添加if语句,这样,如果没有用于此查询的帖子,就会显示一条简单的消息 我的问题是: <ul class="posts"> <?php if ( $spQuery->have_posts() ) while ( $spQuery->have_posts() ) : $spQuery->the_post(); ?> <li><?php the_post_thumbna
<ul class="posts">
<?php if ( $spQuery->have_posts() ) while ( $spQuery->have_posts() ) : $spQuery->the_post(); ?>
<li><?php the_post_thumbnail( 'themename-bw-image' ); ?></li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
我试着这样做:
<ul class="posts">
<?php if ( $spQuery->have_posts() ) while ( $spQuery->have_posts() ) : $spQuery->the_post(); ?>
<li><?php the_post_thumbnail( 'themename-bw-image' ); ?></li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
<?php else : ?>
<p>No Posts Currently Added.</p>
<?php endif; ?>
目前没有添加任何帖子
但是我得到了这个错误:Parse错误:语法错误,意外的T\u ELSE
这里可能做了一些愚蠢的错误,但我认为这是一种有效的方法。添加大括号(或者在:if($spQuery->have_posts())后面加一个冒号,而不是大括号)
目前没有添加任何帖子
<ul class="posts">
<?php if ( $spQuery->have_posts() ) { while ( $spQuery->have_posts() ) : $spQuery->the_post(); ?>
<li><?php the_post_thumbnail( 'themename-bw-image' ); ?></li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
<?php } else { ?>
<p>No Posts Currently Added.</p>
<?php } ?>