# How to get a specific post from a category

**URL:** <https://talk.jekyllrb.com/t/how-to-get-a-specific-post-from-a-category/6561>\
**Category:** Help\
**Created:** [October 12, 2021, 7:18am UTC](https://talk.jekyllrb.com/t/how-to-get-a-specific-post-from-a-category/6561 "2021-10-12T07:18:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stblog](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/stblog/32/3926_2.png) [@stblog](https://talk.jekyllrb.com/u/stblog)\
**Post date:** [October 12, 2021, 7:18am UTC](https://talk.jekyllrb.com/t/how-to-get-a-specific-post-from-a-category/6561/1 "2021-10-12T07:18:00Z")

</div>

Hello,

How can I get a specific post from a category?

Right now I can only use a specific post from all the posts on the site:  
**{% assign post = site.posts [1]%}**

I also need to take 2,3,4 posts from the **news** category  
No loop and offset

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [October 12, 2021, 9:35am UTC](https://talk.jekyllrb.com/t/how-to-get-a-specific-post-from-a-category/6561/2 "2021-10-12T09:35:44Z")

</div>

## Given post

```yaml
---
title: My title
categories: foo bar
---

```

## No loop

I don’t know why you don’t want a loop, it seems odd without the context, but anyway:

```md
{% assign c = site.categories.foo %} <!-- posts in category "foo" -->

- c[1].title <!-- Second item at index 1 -->
- c[2].title
- c[3].title

```

* * *

## Using `slice`

You can get the first 3 posts in `foo` like:

```md
{% assign c = site.categories.foo | slice: 0, 3 %}
{% for p in c %}
- {{ p.title }}
{% endfor %}

```

Add a link!

```md
{% for p in c %}
- [{{ p.title }}]({{ p.url | relative_url }})
{% endfor %}

```

* * *

Or start at 2nd item and get 3 items.

```liquid
{% assign c = site.categories.foo | slice: 1, 3 %}

{% for p in c %}
- {{ p.title }}
{% endfor %}

```

## Offset and limit

Or if you don’t want to use `slice`. Here also getting first 3 items starting at 2nd.

```md
{% for p in site.categories.foo offset: 1 limit: 3 %}
- {{ p.title }}
{% endfor %}

```

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [October 12, 2021, 9:37am UTC](https://talk.jekyllrb.com/t/how-to-get-a-specific-post-from-a-category/6561/3 "2021-10-12T09:37:40Z")

</div>

For interest to explore all items in all categories. From my [Cheatsheet](https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/jekyll/liquid/posts/categories.html)

```auto
<ul>
    {% for c in site.categories %}
        <li>
            <h3>
                {{ c[0] }}
            </h3>
            <ul>
                {% for p in c[1] %}
                    <li>
                        <a href="{{ p.url | relative_url }}">
                            {{ p.title }}
                        </a>
                    </li>
                {% endfor %}
            </ul>
        </li>
    {% endfor %}
</ul>

```

Result

- abc
  - My title
  - My next title

- def
  - Another title

---

<div class="post-metadata">

**Author:** ![stblog](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/stblog/32/3926_2.png) [@stblog](https://talk.jekyllrb.com/u/stblog)\
**Post date:** [October 13, 2021, 4:06pm UTC](https://talk.jekyllrb.com/t/how-to-get-a-specific-post-from-a-category/6561/4 "2021-10-13T16:06:00Z")

</div>

Thanks a lot.  
The first option came in handy for me!

_The cycle is not used, since posts are displayed in the layout, where the post blocks are different from each other._
