I may be misunderstanding your requirements, but the built in ACF functions should handle this for you.
If you're using a flexible content field use something like this to loop through the fields and pick out the layout type:
<?php// check if the flexible content field has rows of dataif(have_rows('flexible_content_field_name')):// loop through the rows of datawhile(have_rows('flexible_content_field_name')):the_row();if(get_row_layout()=='paragraph'):the_sub_field('text');elseif(get_row_layout()=='download'):$file=get_sub_field('file');endif;endwhile;else:// no layouts foundendif;?>
In this example the flexible_content_field_name is the name of the field you setup in ACF and the if/else-if area is where you place your layout code to handle the various flexible content layouts you may have for this field.
Based on your screenshot though, you may not need a flexible layout if the type of content will be the same, just the number of items will be variable then the repeater field should do the job.
If that's the case then the example code should do the trick, I'll customize it to your screenshot:
<?php// check if the repeater field has rows of dataif(have_rows('field_name_goes_here')):// loop through the rows of datawhile(have_rows('field_name_goes_here')):the_row();// display a sub field value?><h3><?phpthe_sub_field('title');?></h3><p><?phpthe_sub_field('paragraph');?></p><?phpendwhile;else:// no rows foundendif;?>
If I misunderstood completely, please let me know.
hey there Kyle! thank you for your reply.
Hmm, yeah I think maybe you misunderstood the use case a little.
I wouldn't know the row layout name will be called 'paragraph'. Cos the client would be creating their own rows. Or adding more rows / removing pre-existing ones. Hence I need something that can iterate through pretty generically without a certain row name ;)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I may be misunderstanding your requirements, but the built in ACF functions should handle this for you.
If you're using a flexible content field use something like this to loop through the fields and pick out the layout type:
In this example the
flexible_content_field_name
is the name of the field you setup in ACF and the if/else-if area is where you place your layout code to handle the various flexible content layouts you may have for this field.Based on your screenshot though, you may not need a flexible layout if the type of content will be the same, just the number of items will be variable then the repeater field should do the job.
If that's the case then the example code should do the trick, I'll customize it to your screenshot:
If I misunderstood completely, please let me know.
hey there Kyle! thank you for your reply.
Hmm, yeah I think maybe you misunderstood the use case a little.
I wouldn't know the row layout name will be called 'paragraph'. Cos the client would be creating their own rows. Or adding more rows / removing pre-existing ones. Hence I need something that can iterate through pretty generically without a certain row name ;)