List Item with individual ID

Hi,

Im working on a project with the slidesjs image slider.
The slider is nested inside every li of a ul. Since the slidesjs only works with and id but needs to be loaded multiple times inside the li, I don’t know how to proceed.

<section id="buch">
 <ul>
    <?php foreach($data->children()->visible() as $buch): ?>
    <li>
    <div class="slides" id="slider">
    </li>
    <?php endforeach ?>
 </ul>
</section>

Is there a way to assign a a individual id for slider? I don’t know how to create a id »foreach«

Eager to hear solutions and thank you in advance
Jannick

Have you tried initializing the slideshows using a class name instead of ids? This should work for most well-written plugins.

If not, you might want to add a counter to the id.

<?php $i = 0; foreach($data->children()->visible() as $buch): ?>
    <li>
        <div class="slides" id="slider<?php echo $i ?>"></div>
    </li>
<?php $i++;   endforeach ?>
1 Like

You could also use a page variable, e.g. the UID, then you don’t need the additional variable:

<div class="slides" id="<?php echo $buch->uid() ?>"></div>

Hi twirx,

thank you very much, it worked out for me that way!

That’s the problem if you learn php only by fiddling with kirby and don’t learn it from the ground up…
What a handy function!