首页上的特色帖子

Featured posts on front page

如何在首页顶部显示特色 post? 接下来是剩下的 posts.

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

这是我的 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/

目前唯一的特色 post 是 如何在 AWS 上安装 Ghost |免费的 Amazon EC2 - 完整指南.

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

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

还通读了这篇文章:The Ghost Blogging 支持论坛:在索引页上首先显示特色 post 还是没找到。

首先感谢来自ghost.slack.com的@subic,他亲切地测试了我的主题并指出了正确的方向。

阅读冗长的讨论后GitHub Ghost Issue: Query (get) helper #4439 recently closed, great news - helpers and filters are being added to Public API v1

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

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

{{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>

这会在顶部显示特色帖子,而另一个单独样式的帖子循环显示在下方。