I am listing all rows and need to add a class to first item for first row, second item for second row, etc.
Row #1
– Title (active)
– Title
– Title
Row #2
– Title
– Title (active)
– Title
Row #3
– Title
– Title
– Title (active)
This is where I am, but I think I am going in the wrong direction..
<?php $rows = get_field( 'produktinfo' ); $i = 0;
if($rows) {
echo '<ul class="links-list">';
foreach($rows as $row) {
$i++;
if( $i == 1) { $class = 'active' ; }
else $class = '';
echo '<li class="' . $class . '"><a href="#' . $row['idblock']. '" class="scroll-js prodlink">' . $row['produktmodell']. '</a></li>';
}
echo '</ul>';
} ?>
Hi @magnusnesse
Is “produktinfo” field is a repeater? Could you please tell me what’s wrong with the code? Maybe you can share the complete code and some screenshots of your field structure.
Thanks!
This reply has been marked as private.
Hi @magnusnesse
The code you shared lists the titles for each row. If you want to set a different class for each row, you need to modify the code that lists the rows, not the titles.
If you don’t understand the logic, please learn more about foreach here: http://php.net/manual/en/control-structures.foreach.php. You can also hire a developer to help you out with it. I’d recommend looking for one on https://studio.envato.com/ or https://www.upwork.com/.
I hope this makes sense.