How do I show pages on my homepage?

Hello,

I’m trying to show pages on my homepage, here’s what I have so far:

{{!< default}}
{{!-- The tag above means: insert everything in this file
into the {body} of the default.hbs template --}}

{{#is "home"}}
    {{#if @site.description}}
    <header class="page-head">
        <h2 class="page-head-title">{{@site.description}}</h2>
    </header>
    {{/if}}
{{/is}}

{{#get "posts" filter="page:true"}}
  {{#foreach posts}}
    {{title}}
    <p>{{excerpt words="33"}}</p>
  {{/foreach}}
{{/get}}

However nothing is displayed on my homepage.

Reason for using pages is I want to display all posts which contain a certain tag on the page, and display this page on my homepage for navigation (similar to wordpress categories).

  • What version of Ghost are you using? 3.2.0

Hi @lmac. Would I be right in saying that you want to only show posts from a certain category on the home page? If so you could leverage the routes file and collections which would save you from making modifications to the theme you’re using, there’s an example over on our docs:

Hi @DavidDarnes, I’m trying to show pages from a certain tag on my homepage.

I checked the docs and that’s how I came up with:

{{#get "posts" filter="page:true"}}
  {{#foreach posts}}
    {{title}}
    <p>{{excerpt words="33"}}</p>
  {{/foreach}}
{{/get}}

However nothing is displayed. I’m using London theme if that helps

To get all pages with a specific tag you’ll want to use the #get helper like so:

{{#get "pages" filter="tag:example"}}
  {{#foreach pages}}
    <h2>{{title}}</h2>
    <p>{{excerpt words="33"}}</p>
  {{/foreach}}
{{/get}}

However if you’re trying to create a navigation I’d suggest you check out the navigation features built into Ghost:

Or if you’re utilising tags to create collections of content I’d suggest using posts with custom collections:

1 Like

Thanks for your reply.

Using the code supplied (with the correct tag) nothing is displayed on my home page. Even if I remove the filter, nothing is displayed.

I’m trying to show pages on my homepage, that contain links to each of my posts.

So for example, my homepage (example.com) will show links to:
example.com/category-1/
example.com/category-2/
and so on…

I have only 1 page, with the correct tag, however nothing is output on the screen. I’m using a home.hbs so the file is being used correctly.

Thank you

In that case you want to just list out the primary tag rather than static pages. Like so:

{{#get "tags" limit="all"}}
    <ul class="tags">
        {{#foreach tags}}
            <li>
                <a href="{{url}}">{{name}}</a>
            </li>
        {{/foreach}}
    </ul>
{{/get}}

Tags have their own pages which list all the posts within them, there’s no need to create pages :slight_smile: