如何在首页顶部显示精选帖子? 其余的帖子紧随其后。
目前,它们显示在分页的每个页面的顶部。
这是我的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}}">»</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}}">»</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 但仍然没有。
答案 0 :(得分:2)
<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>
这会在顶部显示精选帖子,而另一个单独风格的帖子循环显示在下方。
答案 1 :(得分:1)
首先归功于来自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}}