自定义循环不起作用,找不到问题

时间:2013-04-04 作者:Eckstein

我不明白为什么这个自定义循环没有为我显示:。我尝试删除if语句和某些查询参数,但它就是不显示。如果我完全删除循环,页面就会显示布局,所以我知道这是循环本身,我就是找不到问题所在。

有人注意到我做错了什么吗?

    <?php /* Start the Loop */ ?>

<?php 
    query_posts(array( 
        \'post_type\' => \'events\',
        \'showposts\' => 10 ,
        \'meta_key\' => \'event_datestart\',
        \'orderby\' => \'meta_value\' ,
        \'order\' => \'ASC\' ,
    ) );  
?>
<?php while (have_posts()) : the_post(); ?>         
<?php 
    $raweventstart = get_field(\'event_datestart\');
    $raweventend = get_field(\'event_dateend\');

    $eventstart = strtotime("$raweventstart");
    $eventend = strtotime ("$raweventend");
    $now = strtotime("now"); 

    //Check if event is in the future or past.

    if ($eventstart >= $now) {
?>

                <div class="main-area-section-content">

                <div class="event-wrapper">
                        <div class="event-header">
                            <div class="event-date">
                            <?php echo $raweventstart; ?>
                            </div>
                            <div class="venue-name">
                            <?php if (get_field (\'venue_name\') ) { the_field(\'venue_name\'); } ?>
                            </div>
                        </div>
                        <div class="event-content">
                            <div class="event-address">
                            <?php if (get_field (\'venue_address\') ) { the_field(\'venue_address\'); } ?>
                            </div>
                            <div class="venue-phone">
                            <?php if (get_field (\'venue_phone\') ) { the_field(\'venue_phone\'); } ?>
                            </div>
                            <div class="venue-website">
                            <?php if (get_field (\'venue_website\') ) { ?><a href="<?php echo get_field(\'venue_website\'); } ?>">Venue Website</a> 
                            </div>
                            <div class="event-description">
                            <?php if (get_field (\'event_description\') ) { the_field(\'event_description\'); } ?> 
                            </div>
                        </div>
                    </div>



                </div>
            <?php } //end check to see if event is in the past?>
<?php endwhile;?>
<?php wp_reset_query(); ?>  

1 个回复
SO网友:Eckstein

多亏了上面的建议(这是一个简化的版本),这一点起到了作用:

    $args = array(\'post_type\' => \'event\');
    // The Query
    $the_query = new WP_Query( $args );

    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();

结束

相关推荐

Modifying a Loop to Show More

此循环显示主题选项中指定的特定类别中超过4个帖子标题的一篇特色帖子。我想做的是显示4个标题中的所有4个帖子,在4个标题之上。这4个标题来自这段代码<a class=\"listtitle\" href=\"<?php the_permalink() ?>\" rel=\"bookmark\" title=\"<?php printf( esc_attr__( \'Permalink to %s\', \'wpnewspaper\' ), the_title_attribute( \