Php 在最后一行ACF get_row_layout()之前添加一个节

Php 在最后一行ACF get_row_layout()之前添加一个节,php,wordpress,while-loop,advanced-custom-fields,Php,Wordpress,While Loop,Advanced Custom Fields,需要这方面的帮助,因为我试图在最后一行之前添加一个部分,我使用ACF灵活的内容,并且这些行可以互换,所以即使我更改它,我添加的部分仍将始终位于最后一行之前 if( have_rows($content_rows) ): while ( have_rows($content_rows) ) : the_row(); if( get_row_layout() == 'row_one' ): echo 'First row'; endi

需要这方面的帮助,因为我试图在最后一行之前添加一个部分,我使用ACF灵活的内容,并且这些行可以互换,所以即使我更改它,我添加的部分仍将始终位于最后一行之前

if( have_rows($content_rows) ):
    while ( have_rows($content_rows) ) : the_row();

        if( get_row_layout() == 'row_one' ):
            echo 'First row';
        endif;

        if( get_row_layout() == 'row_two' ):
            echo 'Second row';
        endif;

        {need to add a div here and it should show before the last row even if its moved}

        if( get_row_layout() == 'row_three' ):
            echo 'Third row';
        endif;

    endwhile;
endif;

诀窍是在最后一行div之前计算所有行并输出

if( have_rows($content_rows) ):
    $totalCount = count(get_field($content_rows));
    $currentCount = 1;
    while ( have_rows($content_rows) ) : the_row();

        //add div before the last row
        if ($currentCount - 1 === $totalCount) {
            echo "<div></div>";
        }

        if( get_row_layout() == 'row_one' ):
            echo 'First row';
        endif;

        if( get_row_layout() == 'row_two' ):
            echo 'Second row';
        endif;

        if( get_row_layout() == 'row_three' ):
            echo 'Third row';
        endif;

        $fields_count++;
    endwhile;
endif;
if(有行($content\u行)):
$totalCount=计数(获取字段($content\u行));
$currentCount=1;
while(have_rows($content_rows)):the_row();
//在最后一行之前添加div
如果($currentCount-1===$totalCount){
回声“;
}
如果(获取行布局()='row\u one'):
回声“第一排”;
endif;
如果(get_row_layout()=“row_two”):
回声“第二排”;
endif;
如果(获取行布局()='row\u three'):
回声“第三排”;
endif;
$fields_count++;
结束时;
endif;