> ## Content Index
> Fetch the complete content index at: https://getpublii.com/dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# {{#getPosts}} helper

- URL: https://getpublii.com/dev/getposts-helper/
- Published: 2018-12-25T21:48:36.982Z
- Updated: 2024-08-15T21:02:29.540Z
- Description: {{getPosts}} is a helper used to retrieve post data regardless of the current context. Syntax: {{#getPosts "postID1,postID2,postID3" "before" "after"}} ... {{/getPosts}} Example: {{#getPosts "POST\_ID\_1,POST\_ID\_2,POST\_ID\_N" "<ul>" "</ul>"}}…
- Author: Tomasz Dziuda
- Tags: Helpers

**{{getPosts}}** is a helper used to retrieve post data regardless of the current context.

Syntax:

```handlebars
{{#getPosts "postID1,postID2,postID3" "before" "after"}}
...
{{/getPosts}}
```

Example:

```handlebars
{{#getPosts "POST_ID_1,POST_ID_2,POST_ID_N" "<ul>" "</ul>"}}
<li>
    <h2>{{ title }}</h2>
    <div>{{{ excerpt }}}</div>
</li>
{{/getPosts}}
```

Posts are ordered by the ID order in the string.

You can also use the **@index** variable to detect the post number in the specified collection:

```handlebars
{{#getPosts "1,2,3" "<ul>" "</ul>"}}
<li>
    <h2>{{ title }}</h2>
    <div>{{{ excerpt }}}</div>
    {{#checkIf @index '==' 0}}
    <p>IT'S THE FIRST ELEMENT!</p>
    {{/checkIf}}
</li>
{{/getPosts}}
```

The second parameter creates an HTML prefix, and the third parameter creates an HTML suffix for the generated output.

Additionally, it is possible to enhance the dynamic fetching and display of posts by utilizing the [posts dropdown](#INTERNAL_LINK#/post/120) control from the Theme Settings API, in conjunction with the `concatenate` helper to combine query string options with theme option values. This control allows users to select specific posts to be displayed. Integrating this functionality within your theme involves directly referencing the selected posts through the theme configuration. For instance, if you have a posts dropdown control named `postsDropdown` in your Theme Settings, its value can be dynamically used with the `getPosts` helper, as shown below:

```handlebars
{{#getPosts (concatenate  @config.custom.postsDropdown) "<ul>" "</ul>"}}
    <li>
        <h2>{{ title }}</h2>
        <div>{{{ excerpt }}}</div>
    </li>
{{/getPosts}}
```

In this setup, @config.custom.featuredPostsDropdown directly refers to the comma-separated post IDs the user selects through the dropdown control. This approach ensures that the displayed posts can be dynamically controlled via theme settings, offering a high level of customization for theme users.

**IMPORTANT:** It requires availability of the `@website.contentStructure` global variable
