我什至不知道要搜索什么,所以我尝试过的东西并不多,因为我被难住了。
这是循环,获取月份名称,然后对该月份内的事件进行分组。注释 //* Close the Div :
PROBLEM 是问题所在。该代码执行了它应该执行的操作,但列表之前有一个空 div。
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;
最佳答案
您的 while 循环最初将循环一次,并在回显初始开始标记之前回显结束标记。
只需检查 $current_month 是否为空即可修复该问题。
echo !empty($current_month) ? '</div><!-- /events-by-month -->' : null;
关于php - 围绕分组的循环开始处的空结束 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47701109/