Hello,
I want to catch all specific sub_fields from flexible content field and make the menu from them.
Here is the code for my flexible content field:
<?php
if( have_rows('modules') ): while ( have_rows('modules') ) : the_row();
if( get_row_layout() == 'photo' ):
the_sub_field('menu_name'));
the_sub_field('photo'));
elseif( get_row_layout() == 'text' ):
the_sub_field('menu_name'));
the_sub_field('text'));
<?php endif; endwhile; else : endif; ?>
I want to get all the_sub_field(‘menu_name’) and to populate menu from that, like this:
<ul>
<li>1st the_sub_field('menu_name'));</li>
<li>2st the_sub_field('menu_name'));</li>
<li>3st the_sub_field('menu_name'));</li>
<li>4st the_sub_field('menu_name'));</li>
<li>5st the_sub_field('menu_name'));</li>
</ul>
Any help on that?
Maybe something like:
<?php if( have_rows('modules') ): ?>
<?php $menu_items = ''; ?>
<?php while ( have_rows('modules') ) : the_row();
if( get_row_layout() == 'photo' ):
$menu_items .= '<li><img src="' . get_sub_field('photo') . '" alt="' . get_sub_field('menu_name') . '"><li>';
elseif( get_row_layout() == 'text' ):
$menu_items .= '<li>' . get_sub_field('menu_name') . ' ' . get_sub_field('text') . '</li>';
<?php endif; endwhile; ?>
<ul>
<?php echo $menu_items; ?>
</ul>
<?php endif; // end modules has rows ?>
Yeahhhh 🙂 Actually it’s pretty simple solution. Just using the same source code and making output of only menu item sub_field, ignoring all other fields.
Thanks ractoon for your help. I will try it and come back if its solved 🙂
My final code for this issue:
<?php if( have_rows('modules') ): ?>
<ul>
<?php while ( have_rows('modules') ) : the_row();
if( get_row_layout() == 'photo' ):
echo '<li>'.the_sub_field('menu_name') . '<li>';
elseif( get_row_layout() == 'text' ):
echo '<li>' . the_sub_field('menu_name') .'</li>';
endif; endwhile; ?>
</ul>
<?php endif; // end modules has rows ?>
It works perfectly. Thanks ractoon for your help. It was more easier when i was trying to do it 🙂