How to Add Posts onto a Static Page


If you want to put some or all of your posts onto a static page, or posts with a certain tag onto a specific page, here is how you can do that using the Ghost API:

Note: The API is currently in beta. Some things in the post may change as Ghost solidifies how the API will function.

  1. Log into the Ghost admin on you site and create a new static page with the slug (url) and title that you want to use. Leave the actual content blank.
  2. Open up your theme files and create a new file called page-[your-slug].hbs (ex. page-blog.hbs or page-how-to.hbs)
  3. Now, in this theme file, add {{!< default}} to the top to get all the normal HTML in there, and then you are most likely going to want to copy the HTML for formatting the lists of posts from index.hbs. For example, this is what Casper's looks like:

  4. Paste that code into your new page-[slug].hbs file and now we are going to wrap it using the {{get}} helper.
  5. Just above the code you just pasted, paste in:

    {{#get "posts" limit="all" include="author,tags"}}
        {{#foreach posts}}
    

    and right after paste in:

        {{/foreach}}
    {{/get}}
    
  6. Now your code should look something like this:

  7. Now, if you restart Ghost and go to the url of the static page you created, you should see a list of all of your posts!

Bonus step:

  1. If you want to list posts just using a tag, you can add an filter to the {{get}} helper. Here is what it would look like if you wanted to grab posts only with the tag how to:

    The filter can also filter by author and my other things. Here is the full documentation on the filtering.

4. Paste that code into your new `page-[slug].hbs` file and now we are going to wrap it using the `{{get}}` helper. 5. Just above the code you just pasted, paste in: {{#get "posts" limit="all" include="author,tags"}} {{#foreach posts}} and right after paste in: {{/foreach}} {{/get}} 6. Now your code should look something like this: 7. Now, if you restart Ghost and go to the url of the static page you created, you should see a list of all of your posts! Bonus step: 1. If you want to list posts just using a tag, you can add an filter to the `{{get}}` helper. Here is what it would look like if you wanted to grab posts only with the tag `how to`: The filter can also filter by author and my other things. Here is the full documentation on the [filtering](http://api.ghost.org/docs/filter).