【问题标题】:Featured posts on front page头版上的精选帖子
【发布时间】:2015-10-08 19:12:04
【问题描述】:

如何在首页顶部显示精选帖子? 接下来是其余的帖子。

目前它们显示在分页每一页的顶部。

这是我的 loop.hbs:

{{! Previous/next page links - only displayed on page 2+ }}
<div class="extra-pagination inner">
    {{pagination}}
</div>

{{! This is the post loop - each post will be output using this markup }}
{{#foreach posts}}
{{#if featured}}
<article class="{{post_class}} featured">
    <header class="post-header">
        <h2 class="post-title"><a href="{{url}}">{{{title}}}</a></h2>
    </header>
    <section class="post-excerpt">
        <p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">&raquo;</a></p>
    </section>
    <footer class="post-meta">
        {{#if author.image}}<img class="author-thumb" src="{{author.image}}" alt="    {{author.name}}" nopin="nopin" />{{/if}}    
        {{author}}    
        {{tags prefix="on"}}    
        <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>    
    </footer>    
</article>    
{{/if}}    
{{/foreach}}    

{{! This is the post loop - each post will be output using this markup }}
{{#foreach posts}}
{{#unless featured}}
<article class="{{post_class}}">
    <header class="post-header">
        <h2 class="post-title"><a href="{{url}}">{{{title}}}</a></h2>
    </header>
    <section class="post-excerpt">
        <p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">&raquo;</a></p>
    </section>
    <footer class="post-meta">
        {{#if author.image}}<img class="author-thumb" src="{{author.image}}" alt="    {{author.name}}" nopin="nopin" />{{/if}}    
        {{author}}    
        {{tags prefix="on"}}    
        <time clas    s="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>    
    </footer>    
</article>    
{{/unless}}    
{{/foreach}}    

{{! Previous/next page links - displayed on every page }}
{{pagination}}

这是我的博客:http://netsca.pe/

目前唯一的专题文章是如何在 AWS 上安装 Ghost | Amazon EC2 免费 - 完整指南

如您所见,它显示在帖子第三页的顶部,而不是首页的顶部。

我读过Stack Overflow: newest post with specific tag on the front page,但还是不明白。

还阅读了此内容:The Ghost Blogging Support Forum: Show Featured post first on index page ,但仍无处可去。

【问题讨论】:

  • 我知道它可能看不到太多帮助,但您是否尝试过注释掉 {{pagination}} 只是为了看看它是否真的会首先列出特色文章?我在我的身上试过这个,没问题。我试图将其固定在代码中,但我认为分页是按日期顺序对文章进行排序,因此您的特色帖子位于第 3 页。
  • 我确实得到了完全相同的结果,只是没有顶部和底部的“较新”按钮、“Y 页 X”文本和“较旧”按钮。

标签: handlebars.js ghost-blog ghost


【解决方案1】:

{{get}} 的变体对我来说在最新版本的 Ghost 上并不成功。起作用的是:

<section id="main">
              {{#foreach posts}}
              {{#if featured}}
                html for featured posts         
              {{/if}}
              {{/foreach}}

            <div>
              {{#foreach posts}}
              {{^if featured limit="2"}}
                    html for regular post loop
              {{/if}}
              {{/foreach}}
            </div>
</section>

这将精选帖子显示在顶部,而另一个单独样式的帖子循环显示在下方。

【讨论】:

    【解决方案2】:

    首先感谢 ghost.slack.com 的 @subic,他很好地测试了我的主题并为我指明了正确的方向。

    在阅读了最近结束的冗长讨论 GitHub Ghost Issue: Query (get) helper #4439 之后,好消息 - 助手和过滤器正在添加到 Public API v1

    The {{#get}} helper #5619刚刚被合并到master(还不稳定),所以解决方法:

    {{#get "posts" featured="true" as |featured|}}
      {{#foreach featured}}
        ...
      {{/foreach}}
     {{/get}}
    

    【讨论】:

    • 如何给它添加分页?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    相关资源
    最近更新 更多