Search code examples
ghost-blog

Get latest posts inside author looping


I need to create a author list which will hold authors info as well as his/her latest 4 posts. My design will be look like this,

image|545x500

Here is my approch after searching google and digging in docs.

{{#get 'users' limit="all" include="count.posts,posts"}}
        {{#foreach users}}
            {{!-- user datas --}}
            {{name}} , {{bio}} // ... and so on

            {{!-- This user's posts --}}
            {{#foreach posts limit="3"}} 
                <a href="{{ url }}"> {{ title }} </a>
            {{/foreach}}

        {{/foreach}}
{{/get}}

I'm getting user data perfectly but can't get individual user's posts by this,

{{#foreach posts limit="3"}} 
     <a href="{{ url }}"> {{ title }} </a>
{{/foreach}}

Please make me correct. Thanks.


Solution

  • Try this for the posts of any given author:

    {{#get 'users' limit="all" include="count.posts,posts"}}
       {{#foreach users}}              
            {{#get "posts" filter="authors:{{slug}}" limit="3"}}          
                {{#foreach posts}}
                     <a href="{{url}}"> {{title}} </a>
                {{/foreach}}            
              {{/get}}
        {{/foreach}}
    {{/get}}