Home Empty closing div at the beginning of loop surrounding a grouping
Reply: 1

Empty closing div at the beginning of loop surrounding a grouping

Christina
1#
Christina Published in 2017-12-07 17:59:24Z

I don't even know what to search for, so what I've tried is not much since I'm stumped.

This is the loop, getting the month name and then grouping the events inside that month. The comment //* Close the Div : PROBLEM is where the issue is. The code does what it's supposed to do, but there is an empty div before the list.

if ( have_posts() ) : 

    $current_month = '';

    while ( have_posts() ) : the_post();


            if( $current_month != eo_get_the_start( 'm' ) ) :

                    $month = eo_get_the_start('F Y');

                    //* Close the Div : PROBLEM this is where it echos an empty closing div before first month name
                    echo '</div><!-- /events-by-month -->'; 

                    //* Start new group
                    echo '<h3 class="event-month" id="'. $month . '">' . $month . '</h3>';

                    //* Open div around the events in this month
                    echo '<div class="events-by-month" style="border:1px solid green">'; //* inline style so I can see

            endif;

                $current_month = eo_get_the_start('m');

                eo_get_template_part( 'eo-loop-single-event' );


    endwhile;


    //* Genesis Numbered Pagination
    genesis_numeric_posts_nav();

    else:

        echo '<p>'. __( 'No Events', 'joyful' ) . '</p>';

endif;
Lawrence Cherone
2#
Lawrence Cherone Reply to 2017-12-07 18:23:02Z

Your while loop is going to initially loop once and echo out the closing tag before an initial opening tag has been echoed.

Simply checking that $current_month is not empty should fix it.

echo !empty($current_month) ? '</div><!-- /events-by-month -->' : null;

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.336076 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO