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 can I display "Latest Posts" from sections other than "blog"? #105

Open
singhkays opened this issue Oct 24, 2017 · 1 comment
Open
Labels

Comments

@singhkays
Copy link
Contributor

I see the code at the link below controls which categories' posts show up on the main page. However, I have two more categories (monthly roundup of links) that needs to display posts on the front page. How can I add support for categories other than "blog"?

https://raw.githubusercontent.com/nishanths/cocoa-hugo-theme/master/layouts/index.html

@singhkays
Copy link
Contributor Author

@nishanths I figured this out, here's the index.html I am using on my site. I wasn't sure if you want this to be the default behavior for everyone but it made send for my site as I had other categories than just "blog". Hopefully it helps others looking to do this.

{{ partial "header.html" . }}
<section class="main">
    <div class="container">
        <div class="content">
            {{ if .Content }}
                <div class="markdown">
                    {{ .Content }}
                </div>
            {{ end }}
            <!--{{ $totalpostscount := len (where .Data.Pages "Section" "blog") }}-->
            {{ $totalpostscount := len (.Data.Pages) }}
            {{ $latestpostscount := .Site.Params.latestpostscount | default $totalpostscount }}
            {{ if gt $latestpostscount 0 }}
              <div class="page-heading">{{ i18n "latestPosts" }}</div>
                <ul>
                    {{ range (first $latestpostscount ( .Data.Pages.ByPublishDate.Reverse )) }}
                        {{ partial "li.html" . }}
                    {{ end }}
                    {{ if gt $totalpostscount $latestpostscount }}
                        {{ range where .Site.Menus.main "Identifier" "blog" }}
                            <li class="post-item no-bullet">
                                <a id="see-more" {{ printf "href=%q " .URL | safeHTMLAttr }}><span>See more&hellip;</span></a>
                            </li>
                        {{ end }}
                    {{ end }}
                </ul>
              </div>
            {{ end }}
    </div>
</section>
{{ partial "footer.html" . }}

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

No branches or pull requests

2 participants