Support

Account

Home Forums Add-ons Flexible Content Field Reorder Flexible Content Rows in another page

Solved

Reorder Flexible Content Rows in another page

  • I would like to know how to reorder flexible content rows in another page.

    For example I have contact page where you can add address row and email row.

    They are currently ordered as address first, then email.

    But I want to use these two rows in my front page and rearrange them, email first then address.

    My current code is this in front page:

    
    if( have_rows('contact', $page_id) ): while ( have_rows('contact', $page_id) ) : the_row(); ?>
    
    	<?php if( get_row_layout() == 'email' ): ?>
    
    			<a href="mailto:<?php the_sub_field('email'); ?>"><?php the_sub_field('email'); ?></a>
    
    	<?php elseif ( get_row_layout() == 'text' ): ?>
    
               <span class="aadress"><?php the_sub_field('text'); ?></span>
    
    	<?php endif; ?>
    
    <?php endwhile; endif; ?>
    
  • The simplest way to do this would be to add the same field group to the admin of this other page and enter the content there.

    Alternately, you could store the first row in an object buffer and then output in after the second one, however, what will you do if the order is changed on the other page?

    
    <?php 
    
    $buffer = '';
    if( have_rows('contact', $page_id) ): while ( have_rows('contact', $page_id) ) : the_row(); ?>
    
      <?php if( get_row_layout() == 'email' ): ?>
          <?php ob_start(); ?>
          <a href="mailto:<?php the_sub_field('email'); ?>"><?php the_sub_field('email'); ?></a>
          <?php $buffer = ob_get_clean(); ?>
      <?php elseif ( get_row_layout() == 'text' ): ?>
    
               <span class="aadress"><?php the_sub_field('text'); ?></span>
          <?php 
            if ($buffer) {
              echo $buffer;
              $buffer = '';
            }
          ?>
      <?php endif; ?>
    
    <?php endwhile; endif; ?>
    
  • That solved my problem. Thank You.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Reorder Flexible Content Rows in another page’ is closed to new replies.