2

I'm trying to set up having the first entry pull in and then later down the page pull in the remaining posts (as I need to break the loop with other content). I'm a little unsure how to set up pulling in the 'Not firstEntry' for the second part. This is what I'm working with:

{% paginate craft.entries.section('blog').limit(1) as entriesOnPage %}
{% for entry in entriesOnPage %}
{% set firstEntry = craft.entries.section('blog').order('postDate desc').one() %}

{% if entry.id == firstEntry.id and craft.request.getPageNum() == 1 %}
//output first entry
{% endif %}
{% endfor %}

// DO OTHER STUFF

{% paginate craft.entries.section('blog').limit(12) as entriesOnPage %}
{% for entry in entriesOnPage %}

//OUTPUT 12 Entries not including the first

{% endfor %}
3

"Measure twice, cut once" goes the saying... (Kind of the opposite here, but the same principle!) - Fetch your data once, then cut it up how you like using Twig filters. In your case you can fetch the first item from an array with [0] and then slice off that same entry from the start of the same array with |slice(1) like this:

{% paginate craft.entries.section('blog').order('postDate desc').limit(13) as entriesOnPage %}

{% set firstEntry = entriesOnPage[0] %}
{% set theRest = entriesOnPage|slice(1) %}

{# ======================================================================= #}

<h1>{{ firstEntry.title }}</h1>

{% for entry in theRest %}
    {# OUTPUT 12 Entries not including the first #}
    <h2>{{ entry.title }}</h2>
{% 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.