Let's say I have 4 entry types (Article, Video, Photo & Quote). What's the best way to list the latest 5 entries by each entry type?


craft.entries() fetches entries.

To fetch the entries with a given entry type, you use type. So to get the Article entries, either craft.entries.type('Article') or craft.entries({type: 'Article'})

To fetch the latest 5, you want the entries sorted by postDate, descending (this is the default sort order), and then limit that to 5. Combining with the entry type, you have: craft.entries.type('Article').limit(5) or craft.entries({type: 'Article', limit: 5})

And you have four entry types, so might as well loop over those:

{% for entryType in ['Article', 'Video', 'Photo', Quote] %}
  {% set latestFive = craft.entries({
    type: entryType,
    limit: 5
  }) %}

  {% for oneEntry in latestFive %}
    {# list that entry #}
    {{ oneEntry.title}} is of type {{ entryType }}
  {% endfor %}

{% endfor %}

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.