Forum

Thread tagged as: Question, Problem

perch_item_index resets on each pagination page - how to feature only 2 items.

Is there a way to stop perch_item_index being reset on each pagination page? What I am trying to do is the filter results by date but to featured the two latest articles in slightly different layout. See this template;

<perch:before>
<div class="container // stories">
</perch:before>

<perch:if id="perch_item_index" value="3" match="lt">
<!--* DO THE FEATURED BOXES *-->
<perch:template path="content/stories/featured.html" />

<!--* BIT OF TRICK TO CHECK IF THE THIRD ITEM THEN TO DO THE CONTAINER *-->
<perch:if id="perch_item_index" value="2" match="eq">
</div>
<div class="container">
</perch:if>

<perch:else />

<!--* NOW DO THE TEASER BOXES *-->
<perch:template path="content/stories/teaser.html" />
</perch:if>


<perch:after>
</div>
</perch:after>


<perch:after>
    <perch:if exists="paging">
        <div class="pagination pagination--news">
            <perch:template path="pagination/default.html" rescope="parent" />
        </div>
    </perch:if>
</perch:after>

But what is happening is that the first two items on each new pagination page (page 2/3/4 etc) are being featured. I only want to feature the top 2 on the first page.

I did think about using perch_item_first but this wouldn't help me with the second item.

Any ideas?

Thanks, Terry

Terry Upton

Terry Upton 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The perch_item... values are for the set of content being templated. So the first item in the set is always 1. The template doesn't know anything about other data that might have come before or after this set.

Why not test if it's the first page?

https://docs.grabaperch.com/docs/templates/pagination/

Thanks Drew. Yeah another layer of if else and checking if first page works nicely.