I need to add some codes between flexible content fields loop, but I don’t know which is the syntax. I have this code:
<?php if( have_rows('blocks') ):?>
<?php while ( have_rows('blocks') ) : the_row();?>
<?php if( get_row_layout() == 'full_screen' ):?>
<?php elseif( get_row_layout() == 'box' ):?>
<div class="row">
<div class="col-sm-3">
<!--content-->
</div>
</div>
<?php endif;?>
<?php endwhile;
else :
We expect the output to be like this:
<div class="row">
<div class="col-sm-3"><!--content--></div>
</div>
<div class="row">
<div class="col-sm-3"><!--content--></div>
</div>
Which code should I add to get this outcome?
<div class="row">
<div class="col-sm-3"><!--content--></div>
<div class="col-sm-3"><!--content--></div>
</div>
I need to include the generated code in another div
Thank you!
Hi @marco-b
You should be able to achieve that using this code:
<?php if( have_rows('blocks') ):?>
<div class="row">
<?php while ( have_rows('blocks') ) : the_row();?>
<?php if( get_row_layout() == 'full_screen' ):?>
<?php elseif( get_row_layout() == 'box' ):?>
<div class="col-sm-3">
<!--content-->
</div>
<?php endif;?>
<?php endwhile;
</div>
else :
I hope this helps.
Thank you @James for the answer.
Using your code i can include all the layouts inside a <div class=’row’></div> , but i need to include only the “box” layout inside a <div class=’row’></div>, not all the generated code.
If i have this code:
<?php if( have_rows('blocks') ):?>
<div class="row">
<?php while ( have_rows('blocks') ) : the_row();?>
<?php if( get_row_layout() == 'full_screen' ):?>
<div class="fullscreen"><!--content--></div>
<?php elseif( get_row_layout() == 'box' ):?>
<div class="row">
<div class="col-sm-3">
<!--content-->
</div>
</div>
<?php endif;?>
</div>
<?php endwhile;
else :
We expect the output to be like this:
<div class="row">
<div class="fullscreen"><!--content--></div>
<div class="col-sm-3"><!--content--></div>
<div class="col-sm-3"><!--content--></div>
</div>
But i need this:
<div class="fullscreen"><!--content--></div>
<div class="row">
<div class="col-sm-3"><!--content--></div>
<div class="col-sm-3"><!--content--></div>
</div>
Someone can help me?
Thank you!
Hi @marco-b
I believe you can do it like this:
<?php if( have_rows('blocks') ):?>
<?php $i = 0; ?>
<?php while ( have_rows('blocks') ) : the_row();?>
<?php if( get_row_layout() == 'full_screen' ):?>
<div class="fullscreen"><!--content--></div>
<?php elseif( get_row_layout() == 'box' ):?>
<?php if($i == 0){ ?>
<div class="row">
<?php
}
$i++;
?>
<div class="col-sm-3"><!--content--></div>
<?php endif;?>
<?php endwhile;
</div>
else :
Hope this helps!
The topic ‘Insert code between get_row_layout()’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.