Forum

Thread tagged as: Question, Discussion

Nice pagination on grabaperch blog - how did you do that?

The pagination is nice at the bottom of https://grabaperch.com/blog how did you get it to display like that? Can you show us the template?

Simon Clay

Simon Clay 127 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

We're just using page-links.

perch_blog_custom(array(
    'count'      => 10,
    'template'   => 'post_in_list.html',
    'sort'       => 'postDateTime',
    'sort-order' => 'DESC',
    'paginate'   => true,
    'page-links' => true,
));

In post_in_list.html we include a standard set of pagination:

<perch:after>
<perch:template path="pagination/default.html" rescope="parent" />
</perch:after>

which looks like this:

<perch:if exists="paging">
  <ul class="pager cf">
    <perch:if exists="not_first_page">
      <li class="prev"><a href="<perch:content id="prev_url" type="hidden" encode="false" />">Previous</a></li>
    </perch:if>
    <perch:content id="page_links" encode="false" />
    <perch:if exists="not_last_page">
      <li class="next"><a href="<perch:content id="next_url" type="hidden" encode="false" />">Next</a></li>
    </perch:if>
  </ul>
</perch:if>

All very standard.

Simon Clay

Simon Clay 127 points

Thanks, I'm trying to get page links into search results, but using your code above in the search results page I'm only seeing the 'Previous' and 'Next' buttons. I'm not seeing the Page links in-between.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have a page-links.html template in templates/pagination ?

Simon Clay

Simon Clay 127 points

Yes, the standard :

<perch:before><ul></perch:before>
<li<perch:if exists="selected"> class="active"</perch:if>>
    <perch:if exists="spacer">
        <perch:pages id="page_number" />
    <perch:else />
        <a href="<perch:pages id="url" />"><perch:pages id="page_number" /></a>
    </perch:if>
</li>
<perch:after></ul></perch:after>
Drew McLellan

Drew McLellan 2638 points
Perch Support

How many pages of results do you have?

Simon Clay

Simon Clay 127 points

Six pages of results

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, that should be enough.