【问题标题】:Add a section before the last row ACF get_row_layout()在最后一行之前添加一个部分 ACF get_row_layout()
【发布时间】:2020-04-09 16:31:33
【问题描述】:

需要帮助这些人,因为我试图在最后一行之前添加一个部分,我使用的是 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;

【问题讨论】:

    标签: php wordpress while-loop advanced-custom-fields


    【解决方案1】:

    诀窍是在最后一行 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      相关资源
      最近更新 更多