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.
-
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.
-
Open up your theme files and create a new file called
page-[your-slug].hbs
(ex.page-blog.hbs
orpage-how-to.hbs
) -
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 fromindex.hbs
. For example, this is what Casper's looks like: -
Paste that code into your new
page-[slug].hbs
file and now we are going to wrap it using the{{get}}
helper. -
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}}
-
Now your code should look something like this:
-
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:
-
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 taghow to
:The filter can also filter by author and my other things. Here is the full documentation on the filtering.