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

How do I remove or limit the post list on the homepage #34

Closed
zayuim opened this issue Feb 11, 2019 · 5 comments
Closed

How do I remove or limit the post list on the homepage #34

zayuim opened this issue Feb 11, 2019 · 5 comments

Comments

@zayuim
Copy link

zayuim commented Feb 11, 2019

The homepage of an xmin Hugo site contains a list of all posts under all pages. I have some old posts that I don't want to display on the homepage, I was wondering if it was possible to...

  1. Limit what pages it includes posts from? (e.g. only include posts from "posts" and exclude "notes".)
  2. Limit how long the list is? (probably the easiest?)
  3. Remove it altogether?

I would want this to only affect the homepage's list and not to touch the pages own lists.

Thanks! :)

@leerichardson
Copy link

I am also looking to figure this out!

@yihui
Copy link
Owner

yihui commented May 16, 2019

Sorry, I don't have time to answer your specific questions, but this theme has been explained line-by-line in the blogdown book: https://bookdown.org/yihui/blogdown/templates.html

@leerichardson
Copy link

leerichardson commented May 16, 2019

Here's small hack to get rid of it completely (option 3 in @zayuim original list)

  • create a file layouts/_default/list.html that comments out the loop, if you're on the home page:
{{ partial "header.html" . }}

{{if not .IsHome }}
<h1>{{ .Title | markdownify }}</h1>
{{ end }}

{{ .Content }}

{{if not .IsHome }}
<ul>
  {{ range (where .Data.Pages "Section" "!=" "") }}
  <li>
    <span class="date">{{ .Date.Format "2006/01/02" }}</span>
    <a href="{{ .URL }}">{{ .Title | markdownify }}</a>
  </li>
  {{ end }}
</ul>
{{ end }}

{{ partial "footer.html" . }}

One thing I don't understand: How does Hugo decide which template to use, for each page? For example, how did Hugo decide that the first page would use the list.html template?

@hongtaoh
Copy link

hongtaoh commented Nov 8, 2020

To remove the list from the homepage, in hugo-xmin/layouts/_default/list.html , try :

<ul>
  {{ $pages := .Pages }}
  {{ if .IsHome }}{{ $pages = .Site.RegularPages }}{{ end }}
  {{ if not .IsHome}}  <!-- add this line -->
  {{ range (where $pages "Section" "!=" "") }}
  <li>
    <span class="date">{{ .Date.Format "2006/01/02" }}</span>
    <a href="{{ .RelPermalink }}">{{ .Title | markdownify }}</a>
  </li>
  {{ end }}
  {{ end }} <!-- add this line -->
</ul> 

@zayuim
Copy link
Author

zayuim commented Nov 21, 2020

@hongtaoh Thanks, I'll close the thread now.

@zayuim zayuim closed this as completed Nov 21, 2020
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

4 participants