# Create a list of posts grouped by tag

**URL:** <https://forum.ghost.org/t/create-a-list-of-posts-grouped-by-tag/18447>\
**Category:** Themes\
**Created:** [November 23, 2020, 4:31pm UTC](https://forum.ghost.org/t/create-a-list-of-posts-grouped-by-tag/18447 "2020-11-23T16:31:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dannydvd72](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@dannydvd72](https://forum.ghost.org/u/dannydvd72)\
**Post date:** [November 23, 2020, 4:31pm UTC](https://forum.ghost.org/t/create-a-list-of-posts-grouped-by-tag/18447/1 "2020-11-23T16:31:45Z")

</div>

Hi,

Still relatively new to ghost and have been learning about themes. As an exercise, I am trying to produce a page that lists posts grouped by tags:

**tag1**

- post
- post
- post

**tag2**

- post
- post
- post

Here’s the code I’ve been trying to make work:

````
```
    {{#get "tags" limit="all" include="count.posts" order="count.posts desc"}}
        {{#foreach tags as |alltags|}}
            <a href="{{ url }}">
            <h2>{{ name }} <small>({{ count.posts }})</small> {{alltags.slug}}</h2>
            </a>
            {{#get "posts" limit="3" filter="tag:{{alltags.slug}}" include="tags,authors"}}
                <ul>
                    {{#foreach posts}}
                        <li>{{ title }}</li>
                    {{/foreach}}
            </ul>
            {{/get}}
        {{/foreach}}
    {{/get}}
```

````

This is the bit that doesn’t seem to be working, inside the second nested #get call  
filter=“tag:{{alltags.slug}}”

If I leave that in the nested #get posts call, nothing is returned.

If I take the filter out of that #get posts call, it does print out the first 3 posts but its obviously not filtered. Additionally, the {{ alltags.slug }} does populate inside of the nested foreach, so I’m wondering why it does not seem to be populated inside the #get posts call

Should I expect this to work? Getting all tags, looping through the tags and then getting all posts with the current tag in that first loop?

Hope this is clear and thanks in advance for any guidance 😃

---

<div class="post-metadata">

**Author:** ![minimaluminium](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/minimaluminium/32/2652_2.png) [@minimaluminium](https://forum.ghost.org/u/minimaluminium)\
**Post date:** [November 24, 2020, 6:03am UTC](https://forum.ghost.org/t/create-a-list-of-posts-grouped-by-tag/18447/2 "2020-11-24T06:03:37Z")

</div>

Hey Dan,

1. The block parameters are used inside `{{#get}}` helper, not `{{#foreach}}`. It should be:

```plaintext
{{#get "tags" limit="all" include="count.posts" order="count.posts desc" as |alltags|}}
    {{#foreach alltags}}
        ...
    {{/foreach}}
{{/get}}

```

1. The filter parameter for the posts query should be `tag:{{slug}}`, not `tag:{{alltags.slug}}`.

Our Ease theme does the same thing on its homepage. [Here](https://github.com/TryGhost/Ease/blob/master/index.hbs) is the file if you want to look at the code.

---

<div class="post-metadata">

**Author:** ![dannydvd72](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@dannydvd72](https://forum.ghost.org/u/dannydvd72)\
**Post date:** [November 24, 2020, 3:07pm UTC](https://forum.ghost.org/t/create-a-list-of-posts-grouped-by-tag/18447/3 "2020-11-24T15:07:09Z")

</div>

Thank you! I was blind to my typo with the block parameters. I also modified my alltags.slug to just slug and that worked. I will continue to study the docs to shed my obvious misconceptions on how this works.
