0

投稿が存在しない場合、他のメッセージの後にメッセージが表示されることに慣れていますが、なぜ表示されないのかわかりませんか?

コード:

<?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; ?>

ありがとう!

4

2 に答える 2

4

スペシャルWP_Queryを作成しましたが、間違った投稿をチェックしています

if ( have_posts() )

する必要があります

if ( $loop->have_posts() )
于 2012-10-12T21:32:46.493 に答える
2

奇妙な if/while 構文を使用するとどうなるかは正確にはわかりませんが、次のようになります。

endwhile;

あなたはループを終了していると思います、そして はステートメントを終了しています。この種のものが読みやすくなるように、標準と構文を使用することをお勧めします。endwhilewhile;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
    }
?>
于 2012-10-12T21:20:41.590 に答える