# Looping in posts from another file than index.html

**URL:** <https://talk.jekyllrb.com/t/looping-in-posts-from-another-file-than-index-html/1421>\
**Category:** Help\
**Created:** [January 29, 2018, 6:03pm UTC](https://talk.jekyllrb.com/t/looping-in-posts-from-another-file-than-index-html/1421 "2018-01-29T18:03:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![inwardmovement](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/inwardmovement/32/666_2.png) [@inwardmovement](https://talk.jekyllrb.com/u/inwardmovement)\
**Post date:** [January 29, 2018, 6:03pm UTC](https://talk.jekyllrb.com/t/looping-in-posts-from-another-file-than-index-html/1421/1 "2018-01-29T18:03:19Z")

</div>

Is it considered to allow looping in posts from within another file than an `index.html`?

---

<div class="post-metadata">

**Author:** ![Frank](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/frank/32/26_2.png) [@Frank](https://talk.jekyllrb.com/u/Frank)\
**Post date:** [January 29, 2018, 6:28pm UTC](https://talk.jekyllrb.com/t/looping-in-posts-from-another-file-than-index-html/1421/2 "2018-01-29T18:28:37Z")

</div>

You can already loop on posts wherever you want. That’s what archives of related pages do most of the time, it works also for tag and categories pages. Why do you think otherwise?

---

<div class="post-metadata">

**Author:** ![inwardmovement](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/inwardmovement/32/666_2.png) [@inwardmovement](https://talk.jekyllrb.com/u/inwardmovement)\
**Post date:** [January 29, 2018, 7:02pm UTC](https://talk.jekyllrb.com/t/looping-in-posts-from-another-file-than-index-html/1421/3 "2018-01-29T19:02:28Z")

</div>

I have the following structure:

```
categoryA
    | index.md
    | categoryB
        | index.md
        | _posts
            | article.md

```

I use a layout so that the loop adapts to the category to show the relevant posts.  
My loop in `categoryB/index.md` is working, but the same on [article.md](http://article.md) doesn’t work. Any idea why?

---

<div class="post-metadata">

**Author:** ![inwardmovement](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/inwardmovement/32/666_2.png) [@inwardmovement](https://talk.jekyllrb.com/u/inwardmovement)\
**Post date:** [January 29, 2018, 8:41pm UTC](https://talk.jekyllrb.com/t/looping-in-posts-from-another-file-than-index-html/1421/4 "2018-01-29T20:41:16Z")

</div>

You may need more information, so you can take a look at [the repo](https://github.com/inwardmovement/inwardmovement.github.io) if you need. The loop is at [line 26 of the include nav-poemes.html](https://github.com/inwardmovement/inwardmovement.github.io/blob/master/_includes/nav-poemes.html#L26-L28) which is included in two layouts: a) [recueil.html](https://github.com/inwardmovement/inwardmovement.github.io/blob/master/_layouts/recueil.html) and b) [poem.html](https://github.com/inwardmovement/inwardmovement.github.io/blob/master/_layouts/poem.html). The loop outputs correctly in the `index.md` that calls the `recueil.html` layout, but not in the `article.md` that calls the `poem.html` layout.

I checked that the include parameter `nomrecueil` that’s in the loop is well passed through both layouts. No posts are fetched in the second layout with the same loop…

---

<div class="post-metadata">

**Author:** ![inwardmovement](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/inwardmovement/32/666_2.png) [@inwardmovement](https://talk.jekyllrb.com/u/inwardmovement)\
**Post date:** [February 7, 2018, 8:00am UTC](https://talk.jekyllrb.com/t/looping-in-posts-from-another-file-than-index-html/1421/5 "2018-02-07T08:00:41Z")

</div>

[This StackOverflow answer](https://stackoverflow.com/questions/48598809/jekyll-cant-we-loop-in-the-posts-and-display-the-list-from-each-post/48653320#48653320) managed to make the loop work, but through a sinuous workaround…
