Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hiding a page from the posts list #19

Closed
dsebastien opened this issue Jul 11, 2018 · 3 comments
Closed

Hiding a page from the posts list #19

dsebastien opened this issue Jul 11, 2018 · 3 comments

Comments

@dsebastien
Copy link

Hello,

Thanks for the nice theme.
I'm trying to hide a page from the posts list.

I've tried moving it out of the posts folder but it is still listed on the home page.
I've also tried adding "hidden: true" to the front matter, but it didn't go away either.

I'm not too sure I understand everything in here: https://discourse.gohugo.io/t/unwanted-pages-show-up-in-my-list-view/6656
But it looks like the theme should check for whether the hidden flag is set to true or false; is it done by this theme?

Any help is appreciated :)

@dsebastien
Copy link
Author

dsebastien commented Jul 11, 2018

FYI our site is here: https://github.com/NationalBankBelgium/opensource/tree/master and published on github pages from the "docs" folder.

@htr3n
Copy link
Owner

htr3n commented Jul 11, 2018

Hi @dsebastien,

many thanks for your kind words. To hide some pages from the list in the homepage, you should carefully choose their content types. For instance, for my blog, I chose type: "about" for the "About" page to be excluded from the home page. Then I can write the following code:

  <div class="posts">
    {{ range (where .Data.Pages "Type" "<>" "about").GroupBy "Section" }}
    {{ range .Pages }}
      <div class="post">
        <h1 class="post-title"><a href="{{ .RelPermalink }}">{{ .Title }}</a></h1>
        <span class="post-date">
          {{ .Date.Format (.Site.Params.dateformat | default "Jan 02, 2006") }}
        </span>
          {{ .Summary }}
        {{ if .Truncated }}
        <div class="read-more-link">
            <a href="{{ .RelPermalink }}">Read More…</a>
        </div>
        {{ end }}
        </div>
        {{ end }}
     {{ end }}
  </div>

In case you want to exclude more types, then the syntax of {{ range where ...}} must be changed. For example, please have a look at the code for my blog where I want to exclude "About" and "Porfolio" too.

  <div class="posts">
    {{ range (where .Data.Pages "Type" "not in" (slice "about" "portfolio")).GroupBy "Section" -}}
    {{ range .Pages }}
      <div class="post">
        <h1 class="post-title"><a href="{{ .RelPermalink }}">{{ .Title }}</a>{{ if .Draft }}<sup> <i class="fas fa-pen-square fa-xs"></i></sup>{{ end }}</h1>
        <span class="post-date">
          {{- .Date.Format (.Site.Params.dateformat | default "Jan 02, 2006") -}}
        </span>
          {{ .Summary }}
        {{- if .Truncated }}
        <div class="read-more-link">
            <a href="{{ .RelPermalink }}">Read More…</a>
        </div>
        {{- end }}
        </div>
        {{- end -}}
     {{- end }}
  </div>

Hope this helps.

@htr3n
Copy link
Owner

htr3n commented Jul 16, 2018

I will close this issue for now. Please reopen or ask further questions as you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants