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 >
<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
CodePudding user response:
Say you have an array of rules;
$rules = [
"Hallways and transitional spaces are best...",
"It is best to keep expensive furnishings such...",
"If you want furnishings and accessories to be a bold source...",
"Neutral furnishings and accessories? You can afford...",
];
<ol >
<?php
if(count($rules) > 0):
foreach($ruels as $rule) {
echo '<li>' . $rule . '</li>';
}
else
echo '<li> No Instruction Found </li>'
?>
</ol>
CodePudding user response:
Just add echo '<ol >';
before while cycle and echo '</ol>';
after.
<?php
// Check rows exists.
if(have_rows('rules')):
echo '<ol >';
// 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;
echo '</ol>';
// No value.
else :
// Do something...
endif;
?>