1

I've got the pagination function working nicely for a simple for loop of news entries. However I want to split the template up into the first 2 entries as featured items then the next 6 as smaller items. As I paginate through the entries I'd like to keep that layout, however it seems that I cannot use paginatedEntries.limit(2) or paginatedEntries.limit(6).offset(2). Is there another way of doing this?

{% paginate craft.entries.section('news').limit(8) as paginatedEntries %}
<section class="two-col">
    <div class="firaslant"><h1>News</h1></div>

        {% for entry in paginatedEntries.limit(2) %}
            {# Show first 2 entries #}
        {% endfor %}    
    </section>

    <aside class="two-col-o">
        {% set tagentries = craft.entries.section('news').limit(null) %}
        {% if craft.tags.relatedTo(tagentries)|length %}
            {% import "_macros/_news.twig" as news %}
            {{ news.tags(tagentries, 'News', 'news') }}
        {% endif %}
        <div class="searchbox">
            <h3>Search in News</h3>
            {% import "_macros/_search.twig" as searchForm %}
            {{ searchForm.simple('news') }}
        </div>

        {% import "_macros/_util.twig" as util %}
        {% if currentUser %}
            {{ util.link('/member-news', 'Browse Member News Articles') }}
        {% endif %}

    </aside>

    {# 6 entries as grid #}
    <div class="clear">
        {% for entry in paginatedEntries.offset(2) %}
                {# Show next 6 articles #}
        {% endfor %}
    </div>


        {% if paginate.prevUrl %}<a href="{{ paginate.prevUrl }}" class="paginate-nav">Previous Page</a>{% endif %}
        {% if paginate.nextUrl %}<a href="{{ paginate.nextUrl }}" class="paginate-nav">Next Page</a>{% endif %}
{% endpaginate %}

As soon as I remove .offset(2) or .limit(2) the code functions correctly without errors.

5

You could use Twig's Slice function.

{% set firstTwo = paginatedEntries|slice(0,2) %}
{% set lastFour = paginatedEntries|slice(2,4) %}

Then loop over firstTwo for your first items.

{% for entry in firtTwo %}
   {# Show first 2 entries #}
{% endfor %} 

Loop over lastFour for your final items.

{% for entry in lastFour %}
   {# Show next 6 articles #}
{% 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.