Home › Forums › Add-ons › Repeater Field › Change class of element depending on amount of Repeater Field items › Reply To: Change class of element depending on amount of Repeater Field items
You’ve got more there than you need and your additional ifs are complicating it.
if ($row_count) {
$size = (int)12/$row_count;
}
This calculates the width of the row
if there is 1 row the result is 12 (col-12)
if there is 2 rows the result is 6 (col-6)
3 result 4 (col-4)
4 result 3 (col-3)
5 result 2 (actually 2.4 rounded to int) (col-2)
6 result 2 (col-2)
The only thing I did here was to add
if ($size < 2) {
//force minimum of col-lg-2
$size = 2;
}
assuming you did not want to have a column smaller than that.
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.