# Numbers of projects in loop

**URL:** <https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 13, 2018, 10:43am UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961 "2018-03-13T10:43:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![malin](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@malin](https://forum.getkirby.com/u/malin)\
**Post date:** [March 13, 2018, 10:43am UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961/1 "2018-03-13T10:43:19Z")

</div>

Hallo,  
i would like to create carousel with 6 projects on one slide, but i can create only one project on the slide, Mayby somoeone help me 🙂

This is the fragment of code:

```
<div class="carousel-inner">
					<?php foreach($projects as $project): ?>
						<div class="carousel-item projectitem">

							<ul class="row projects">

								<li class="project mt-3 mt-lg-4 col-12 col-md-6 col-lg-4">
									<a href="<?= $project->url() ?>" class="project-href">
									<?php if($image = $project->images()->sortBy('sort', 'asc')->first()): $thumb = $image->crop(500, 300); ?>
									<img src="<?= $thumb->url() ?>" class="img-fluid zdjproject" alt="<?= $project->title()->html() ?>">
									<?php endif ?>
									<div class="project-title">
									<h3 class="project-name"><?= $project->title()->html() ?></h3>
									</div>
									</a>
								</li>

							</ul>

						</div>
					<?php endforeach ?>
				</div>

```

.carousel-inner - hold all of the slides  
.carousel-item projectitem - is one of the slides  
li - one of six projects

I don’t know how can i create the lop with six li in one .carousel-item

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 13, 2018, 10:49am UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961/2 "2018-03-13T10:49:14Z")

</div>

your foreach loop has to be moved to wrap the li tags instead of the carousel item container. you might want to limit your number of projects as well using `$projects->limit(6)`

---

<div class="post-metadata">

**Author:** ![malin](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@malin](https://forum.getkirby.com/u/malin)\
**Post date:** [March 13, 2018, 10:53am UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961/3 "2018-03-13T10:53:05Z")

</div>

Ok, Thank You, but How can I create next .carousel-item with next 6 items?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 13, 2018, 10:59am UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961/4 "2018-03-13T10:59:37Z")

</div>

what is supposed to be in the carousel items and what in the li tags? do you want to create groups of six projects each?

---

<div class="post-metadata">

**Author:** ![malin](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@malin](https://forum.getkirby.com/u/malin)\
**Post date:** [March 13, 2018, 11:07am UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961/5 "2018-03-13T11:07:57Z")

</div>

Exactly. I have group of projects (their quantity is growing) and i have to group them into 6  
Into the li I have first image of project and title

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 13, 2018, 11:12am UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961/6 "2018-03-13T11:12:00Z")

</div>

Then `chunk()` is what you are looking for: [https://getkirby.com/docs/cheatsheet/pages/chunk](https://getkirby.com/docs/cheatsheet/pages/chunk)

```auto
<?php
$chunks = $projects->chunk(6);
<div class="carousel-inner">
<?php foreach($chunks as $chunk): ?>
  <div class="carousel-item projectitem">

  <ul class="row projects">
  <?php foreach($chunk as $project): ?>
    <li class="project mt-3 mt-lg-4 col-12 col-md-6 col-lg-4">
      <a href="<?= $project->url() ?>" class="project-href">
        <?php if($image = $project->images()->sortBy('sort', 'asc')->first()): $thumb = $image->crop(500, 300); ?>
          <img src="<?= $thumb->url() ?>" class="img-fluid zdjproject" alt="<?= $project->title()->html() ?>">
        <?php endif ?>
        <div class="project-title">
          <h3 class="project-name"><?= $project->title()->html() ?></h3>
         </div>
        </a>
      </li>
      <?php endforeach ?>
    </ul>

    </div>
  <?php endforeach ?>
</div>

```

---

<div class="post-metadata">

**Author:** ![malin](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@malin](https://forum.getkirby.com/u/malin)\
**Post date:** [March 13, 2018, 11:15am UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961/7 "2018-03-13T11:15:04Z")

</div>

You are my Hero 🙂  
It works perfectly. Many Many Thanks

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:28pm UTC](https://forum.getkirby.com/t/numbers-of-projects-in-loop/9961/8 "2025-02-06T17:28:40Z")

</div>


