# Modifying the first item in a loop

**URL:** <https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 4, 2016, 11:45am UTC](https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509 "2016-03-04T11:45:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![residentmeevil](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/residentmeevil/32/1794_2.png) [@residentmeevil](https://forum.getkirby.com/u/residentmeevil)\
**Post date:** [March 4, 2016, 11:45am UTC](https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509/1 "2016-03-04T11:45:57Z")

</div>

Hey all.

I’m trying to list out a number of blog posts onto a page.

For the first link, I want to make the markup different to the rest of the items.

However, I can’t seem to specify the first item in a list to be different from the rest.

I tried this:

```
   <?php

      $items = $page->grandChildren();
      $first = $items->first();

      ?>

 <ul>
        <?php foreach($items as $item): ?>

          <?php if($item == $first) ?>
              <h1>First item</h1>

          <?php else ?>

        <li>

            <h1>Every other item</h1>
        </li>

        <?php endforeach ?>
      </ul>

```

However, It didn’t work.

Any help would be greatly appreciated!

---

<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 4, 2016, 12:00pm UTC](https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509/2 "2016-03-04T12:00:00Z")

</div>

Not tested but you could try:

```php
<?php if($item->is($first)) ?>

```

---

<div class="post-metadata">

**Author:** ![residentmeevil](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/residentmeevil/32/1794_2.png) [@residentmeevil](https://forum.getkirby.com/u/residentmeevil)\
**Post date:** [March 4, 2016, 12:00pm UTC](https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509/3 "2016-03-04T12:00:59Z")

</div>

That didn’t work 😔

But thanks for the super quick response!

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [March 4, 2016, 12:05pm UTC](https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509/4 "2016-03-04T12:05:44Z")

</div>

What you could do is to completely separate the two cases:

```auto
<ul>
  <li>
     <?php $item = $page->grandChildren()->first() ?>
     <h1>First item</h1>
  </li>
  
  <?php foreach($page->grandChildren()->offset(1) as $item): ?>
    <li>
      <h1>Every other item</h1>
    </li>
  <?php endforeach ?>
</ul>

```

---

<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 4, 2016, 12:10pm UTC](https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509/5 "2016-03-04T12:10:03Z")

</div>

What exactly does not work in my solution? It should actually work.

BTW. You should wrap your if-statement within a li tag, not outside of it.

---

<div class="post-metadata">

**Author:** ![residentmeevil](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/residentmeevil/32/1794_2.png) [@residentmeevil](https://forum.getkirby.com/u/residentmeevil)\
**Post date:** [March 4, 2016, 12:14pm UTC](https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509/6 "2016-03-04T12:14:38Z")

</div>

This worked perfectly, thanks so much!

---

<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:00pm UTC](https://forum.getkirby.com/t/modifying-the-first-item-in-a-loop/3509/7 "2025-02-06T17:00:02Z")

</div>

Archived on February 6, 2025, 5:00pm UTC


