Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 反向ACF灵活内容循环_Php_Wordpress_Advanced Custom Fields_Acfpro - Fatal编程技术网

Php 反向ACF灵活内容循环

Php 反向ACF灵活内容循环,php,wordpress,advanced-custom-fields,acfpro,Php,Wordpress,Advanced Custom Fields,Acfpro,我正在使用高级自定义字段和灵活的内容,我想知道如何在php中逆转这个循环,所以最新的文章就在顶部。就像wordpress中的帖子一样。谢谢大家! <?php if( have_rows('article_content') ): ?> <?php while( have_rows('article_content') ): the_row(); ?> <?php if( get_row_layout() == 'article') : ?&

我正在使用高级自定义字段和灵活的内容,我想知道如何在php中逆转这个循环,所以最新的文章就在顶部。就像wordpress中的帖子一样。谢谢大家!

<?php if( have_rows('article_content') ): ?>
    <?php while( have_rows('article_content') ): the_row(); ?>

        <?php if( get_row_layout() == 'article') : ?>

            <a href="<?php the_sub_field('link'); ?>" class="article">
                <?php $att = get_sub_field('image');?>
                <?php $image = wp_get_attachment_image_src( $att, 'article-crop' ); ?>
                <img src="<?php echo $image[0]; ?>">
                <h3><?php the_sub_field('title'); ?></h3>
            </a>

        <?php elseif( get_row_layout() == 'html' ): ?>
              <?php the_sub_field('html_code'); ?>

        <?php endif; ?>
    <?php endwhile; ?>
<?php endif; ?>

我可以想到两种解决方案

  • get_字段('article_content')
    存储在一个数组中,通过访问数组中的数据而不是使用ACF函数来反转它并显示行

  • 使用
    ob\u start()
    ob\u get\u contents()
    ob\u end\u clean()
    将每行的html存储在数组中并反转。我更喜欢这个解决方案,因为您可以使用ACF函数

  • 我使用第二种解决方案修改了您的代码:

      <?php 
     $rows_array = array();
     if( have_rows('article_content') ): ?>
            <?php while( have_rows('article_content') ): the_row(); 
              ob_start();
            ?>
    
            <?php if( get_row_layout() == 'article') : ?>
    
                <a href="<?php the_sub_field('link'); ?>" class="article">
                    <?php $att = get_sub_field('image');?>
                    <?php $image = wp_get_attachment_image_src( $att, 'article-crop' ); ?>
                    <img src="<?php echo $image[0]; ?>">
                    <h3><?php the_sub_field('title'); ?></h3>
                </a>
    
            <?php elseif( get_row_layout() == 'html' ): ?>
                  <?php the_sub_field('html_code'); ?>
    
            <?php endif; ?>
        <?php 
           $rows_array[] = ob_get_contents();
           ob_end_clean(); 
           endwhile; 
        ?>
     <?php 
       $rows_reversed_array = array_reverse($rows_array);
       echo implode('', $rows_reversed_array);
     ?>
    <?php endif; ?>
    


    这是做同样事情的较短方法

    我能想到两种解决方案

  • get_字段('article_content')
    存储在一个数组中,通过访问数组中的数据而不是使用ACF函数来反转它并显示行

  • 使用
    ob\u start()
    ob\u get\u contents()
    ob\u end\u clean()
    将每行的html存储在数组中并反转。我更喜欢这个解决方案,因为您可以使用ACF函数

  • 我使用第二种解决方案修改了您的代码:

      <?php 
     $rows_array = array();
     if( have_rows('article_content') ): ?>
            <?php while( have_rows('article_content') ): the_row(); 
              ob_start();
            ?>
    
            <?php if( get_row_layout() == 'article') : ?>
    
                <a href="<?php the_sub_field('link'); ?>" class="article">
                    <?php $att = get_sub_field('image');?>
                    <?php $image = wp_get_attachment_image_src( $att, 'article-crop' ); ?>
                    <img src="<?php echo $image[0]; ?>">
                    <h3><?php the_sub_field('title'); ?></h3>
                </a>
    
            <?php elseif( get_row_layout() == 'html' ): ?>
                  <?php the_sub_field('html_code'); ?>
    
            <?php endif; ?>
        <?php 
           $rows_array[] = ob_get_contents();
           ob_end_clean(); 
           endwhile; 
        ?>
     <?php 
       $rows_reversed_array = array_reverse($rows_array);
       echo implode('', $rows_reversed_array);
     ?>
    <?php endif; ?>
    


    这是做同样事情的较短方法

    我看不到任何显示此代码的帖子?这只是没有posts关系的自定义字段。嘿,Alexis,是的,没有posts。这只是acf灵活的内容,我想尊重它。我看不到任何文章,将与此代码显示?这只是没有posts关系的自定义字段。嘿,Alexis,是的,没有posts。这只是acf灵活的内容,我想尊重它。
    $rows_array[] = ob_get_clean();