if语句后关闭行div

时间:2015-01-29 13:59:16

标签: php wordpress wp-query

好的,所以我做了一个查询,得到了截止日期的不同块,所有截止日期都应该在一行内。我设法让查询工作我想如何,但唯一的问题是我找不到一种方法来关闭行div()查询完成后..

我在查询末尾添加了一个

echo "</div>";wp_reset_postdata();

但问题是,当查询中有多个项目时,它已经在第一个项目之后关闭了div。

观看此页面以获取示例:http://awardwinningdesignersbe.webhosting.be/deadlines/

以下是查询:

                <?php
                    $blogtime = types_render_field('datum-deadline', array("format" => "Y", "style" => "text"));
                    $prev_limit_year = $blogtime - 1;
                    $prev_month = '';
                    $prev_year = '';

                    $args = array(
                             'post_type' => 'deadline',
                             'meta_key' => 'wpcf-datum-deadline',
                             'order_by' => 'meta_value',
                             'field' => 'slug'
                    );
                    $postsbymonth = new WP_Query($args);

                    while($postsbymonth->have_posts()) {

                        $postsbymonth->the_post();

                        if(types_render_field('datum-deadline', array("format" => "F", "style" => "text")) != $prev_month || types_render_field('datum-deadline', array("format" => "Y", "style" => "text")) != $prev_year && types_render_field('datum-deadline', array("format" => "Y", "style" => "text")) == $prev_limit_year) {
                                       echo "<div class='row deadlinerow'><h2>".types_render_field('datum-deadline', array("format" => "F, Y", "style" => "text"))."</h2>\n\n";
                            }


                        ?>
                                <div class="small-12 medium-6 large-4 columns deadline">
                                    <div class="row">
                                        <div class="small-4 medium-5 large-4 columns deadline-date">
                                            <div class="deadline-cell">
                                                <span><?php echo types_render_field('datum-deadline', array("format" => "d", "style" => "text")); ?></span>
                                                <span><?php echo types_render_field('datum-deadline', array("format" => "M", "style" => "text")); ?></span>
                                            </div>
                                        </div>
                                        <div class="small-8 medium-7 large-8 columns deadline-info">
                                            <div class="inner">
                                                <h3 class="post-title"><?php the_title(); ?></h3>
                                                    <ul class="deadline-cat">
                                                    <?php 
                                                        $args = array(
                                                        'show_option_all'    => '',
                                                        'order'              => 'ASC',
                                                        'style'              => 'list',
                                                        'show_count'         => 0,
                                                        'hide_empty'         => 1,
                                                        'use_desc_for_title' => 1,
                                                        'child_of'           => 0,
                                                        'feed'               => '',
                                                        'feed_type'          => '',
                                                        'feed_image'         => '',
                                                        'exclude'            => '',
                                                        'exclude_tree'       => '',
                                                        'include'            => '',
                                                        'hierarchical'       => 1,
                                                        'title_li'           => __( '' ),
                                                        'show_option_none'   => __( 'No categories' ),
                                                        'number'             => null,
                                                        'echo'               => 1,
                                                        'depth'              => 0,
                                                        'current_category'   => 0,
                                                        'pad_counts'         => 0,
                                                        'taxonomy'           => 'deadline-category',
                                                        'walker'             => null
                                                        );
                                                        wp_list_categories( $args ); 
                                                    ?>
                                                    </ul>
                                                <a href="<?php the_permalink(); ?>" class="meerinfo">Meer Info</a>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                    <?php
                        $prev_month = types_render_field('datum-deadline', array("format" => "F", "style" => "text"));
                        $prev_year = types_render_field('datum-deadline', array("format" => "Y", "style" => "text"));
                        echo "</div>";
                        wp_reset_postdata();
                    }
                    ?>

如果有人可以指出我的方向很好,那会很棒。)

提前致谢! Jannik

1 个答案:

答案 0 :(得分:1)

我添加此代码段供您用作快速参考,只需复制和粘贴...我添加了一个计数值,以便您知道何时有多个帖子。它将结束第一个div,然后根据你的原始开始一个新的div。试试这个。

<?php

$count = 0;
while($postsbymonth->have_posts()) {
    $postsbymonth->the_post();

    if(types_render_field('datum-deadline', array("format" => "F", "style" => "text")) != $prev_month || types_render_field('datum-deadline', array("format" => "Y", "style" => "text")) != $prev_year && types_render_field('datum-deadline', array("format" => "Y", "style" => "text")) == $prev_limit_year) {
        if($count > 0){
            $count = 0;
            echo "</div>";
        }
    echo "<div class='row deadlinerow'><h2>".types_render_field('datum-deadline', array("format" => "F, Y", "style" => "text"))."</h2>\n\n";
        }

    $count++;

        ?>
...

    <?php
    $prev_month = types_render_field('datum-deadline', array("format" => "F", "style" => "text"));
    $prev_year = types_render_field('datum-deadline', array("format" => "Y", "style" => "text"));
    wp_reset_postdata();
}
?>