0

In my loop.hbs template I'm trying to get Ghost to pin posts that have the tag "Top" to the top. I'm using the {{#has}} helper combined with a {{#foreach posts}}.

See code below. The behaviour I'm getting though is that only the {{^has tag="Top"}} (i.e. the second foreach loop) is working.

Any clues as to what I might be doing wrong?

{{#foreach posts}}
    {{#has tag="Top"}}
        <article class="{{post_class}} top-post" style="background-color:lightgray">
            <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>
    {{/has}}
{{/foreach}}

{{! All the code above doesn't seem to be working.  Only the below code outputs posts to the blog homepage }}
{{#foreach posts}}
     {{^has tag="Top"}}
        <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 class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
            </footer>
        </article>
    {{/has}}
{{/foreach}}
4

1 回答 1

0

解决方案是将第一块代码包装在{{#get}}包装器中,即

{{#get "posts" include="tags,author" filter="featured:true" limit="all" as |featured|}}{{/get}}

以下要点将带有“top”标签的帖子固定在 Ghost 博客的顶部(仅在第 1 页),并将帖子标记为精选(但没有“top”标签),并按默认时间顺序将它们与其他帖子一起包含。

https://gist.github.com/anonymous/386c7eb445cc97a45a1ea0ff56898ec6

于 2016-04-11T00:00:16.603 回答