1

I have a blog section on my site and would like a "More posts by this author" list. How would I go about this, the logic is clear but the syntax to write for it is not forthcoming.

5

In order to display all other entries by an author except the current one, you will need to perform another step — either by filtering out the current entry from the query or adding a conditional.

{% set authorId = entry.author.id %}
{% set allEntryIds = craft.entries.section('blog').authorId(authorId).limit(null).ids() %}
{% set otherEntryIds = allEntryIds|without(entry.id) %}
{% set otherEntries = craft.entries.section('blog').id(otherEntryIds) %}

<ul>
    {% for entry in otherEntries %}
        <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}
</ul>

or

{% set authorId = entry.author.id %}
{% set authorEntries = craft.entries.section('blog').authorId(authorId).limit(null) %}
<ul>
    {% for authorEntry in authorEntries %}
        {% if not authorEntry.id == entry.id %}
            <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
        {% endif %}
    {% endfor %}
</ul>
| improve this answer | |
2

You can get entries by an author like this:

{% set authorPosts = craft.entries.section('posts').authorId(entry.authorId) %}

I think this returns an ElementCriteriaModel so you could do things like .first() .limit(1) etc but you can use it in a twig loop as is.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.