Home › Forums › Add-ons › Repeater Field › ACF Repeater max 6 items display inside table › Reply To: ACF Repeater max 6 items display inside table
Your if/else should look something like this
if (count($row_html) <= 2) {
echo 'test 2 items';
} elseif (count($row_html) <= 3) {
echo 'test 3 items';
} else {
echo 'test';
}
you could make that simpler to type and read by doing
$count = count($row_html);
if ($count <= 2) {
echo 'test 2 items';
} elseif ($count <= 3) {
echo 'test 3 items';
} else {
echo 'test';
}
you can simplify it more by using a switch statement which is easier to read when you have a lot of conditions than an if/elseif statement
switch (count($row_html) {
case 1:
echo '1 block';
break;
case 2:
echo '2 blocks';
break;
case 3:
echo '3 blocks';
break;
case 4:
echo '4 blocks';
break;
case 5:
echo '5 blocks';
break;
case 6:
echo '6 blocks';
break;
}
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.