I am using the repeater field of wordpress’ advance custom fields. I have an ordered list. The list items are generated using the repeater field. This is how the static html looks:
<ol class="instructions">
<li>Hallways and transitional spaces are best...</li>
<li>It is best to keep expensive furnishings such...</li>
<li>If you want furnishings and accessories to be a bold source...</li>
<li>Neutral furnishings and accessories? You can afford...</li>
</ol>
The list items have styled numbers beside them.
I am struggling to put the ol together with php as I am very new to learning this language. This is what I have done so far.
<?php
// Check rows exists.
if(have_rows('rules')):
// Loop through rows.
while(have_rows('rules')) : the_row();
// Load sub field value.
$rule = get_sub_field('rule');
// Do something...
echo '<li>' . $rule . '</li>';
// End loop.
endwhile;
// No value.
else :
// Do something...
endif;
?>
How do I echo the php li(s) within the ol and give the ol a class of instructions within my php code?
Thank you for any answers. Very grateful <3
2
Answers
Just add
echo '<ol class="instructions">';
before while cycle andecho '</ol>';
after.Say you have an array of rules;