Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress循环不显示';其他';当没有职位存在时_Php_Wordpress_Loops - Fatal编程技术网

Php Wordpress循环不显示';其他';当没有职位存在时

Php Wordpress循环不显示';其他';当没有职位存在时,php,wordpress,loops,Php,Wordpress,Loops,当没有帖子存在时,我习惯于在else之后看到消息,我不知道为什么现在不显示它 代码: 蓝鸟图书可能很快就会来到你附近的一个社区 我们目前正在计划下一季的日程安排。新的旅游日期将在确认后发布到此页面。同时,欢迎您查询演出和节目!如果您有兴趣让蓝鸟参观您的企业、学校或特殊活动,请联系我们 谢谢 我不确定使用奇怪的if/while语法时会发生什么,但是: endwhile; 我认为您的endwhile正在结束while循环,而结束if语句。我建议使用标准的{和}语法,这样这类内容更容易阅读: &

当没有帖子存在时,我习惯于在else之后看到消息,我不知道为什么现在不显示它

代码:


蓝鸟图书可能很快就会来到你附近的一个社区
我们目前正在计划下一季的日程安排。新的旅游日期将在确认后发布到此页面。同时,欢迎您查询演出和节目!如果您有兴趣让蓝鸟参观您的企业、学校或特殊活动,请联系我们


谢谢

我不确定使用奇怪的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
    }
?>

蓝鸟图书可能很快就会来到你附近的一个社区
我们目前正在计划下一季的日程安排。新的旅游日期将在确认后发布到此页面。同时,欢迎您查询演出和节目!如果您有兴趣让蓝鸟参观您的企业、学校或特殊活动,请联系我们


我不确定使用奇怪的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
    }
?>

蓝鸟图书可能很快就会来到你附近的一个社区
我们目前正在计划下一季的日程安排。新的旅游日期将在确认后发布到此页面。同时,欢迎您查询演出和节目!如果您有兴趣让蓝鸟参观您的企业、学校或特殊活动,请联系我们

您进行了一次特殊的
WP\u查询
,但正在检查错误的帖子 应该是

if ( $loop->have_posts() )
您进行了一次特殊的
WP\u查询
,但正在检查错误的帖子 应该是

if ( $loop->have_posts() )

也许现在有帖子了。您最近是否更改了代码?请尝试使用标准的if-else语句而不是速记。@asad no posts,删除所有帖子以确保安全。没有更改代码。。在我做过的其他网站上工作,不确定为什么不在这个网站上工作。@McMastermind 1下面的回答显示,我尝试过,评论说我更喜欢那个代码,但它没有解决问题:/也许现在有帖子了。您最近是否更改了代码?请尝试使用标准的if-else语句而不是速记。@asad no posts,删除所有帖子以确保安全。没有更改代码。。在我做过的其他网站上工作,不确定为什么不在这个网站上。@McMastermind 1下面的回答显示,我尝试过,评论说我更喜欢那个代码,但它并没有解决问题:/I更喜欢这种格式!这肯定更有意义。然而,它并没有解决问题:/@stephen给出了解决方案,但是我真的很欣赏这段代码,并将永远使用它!我更喜欢这种格式!这肯定更有意义。然而,它并没有解决问题:/@stephen给出了解决方案,但是我真的很欣赏这段代码,并将永远使用它!