Forum

Thread tagged as: Question, Gallery

Can't figure out where to put pagination links for gallery

I have this code to show all albums and their contents on one page:

<ul id="albumdisplay">
<?php
$opts = array(
'skip-template'=>true,
'paginate'=>true,
'count'=>20,
'sort'=>'albumID',
'sort-order'=>'DESC'
);
$albums = perch_gallery_album_listing($opts);

foreach($albums as $album) {
$opts = array(
'template'=>'image-list.html'
);
perch_gallery_album($album['albumSlug'], $opts);
}
?>
</ul>

image-list.html is:

<perch:before>
    <li class="gallery"><a href="<perch:gallery id="main" />" title="<perch:if exists="extraInfo"><perch:gallery id="extraInfo" /><perch:else /><perch:gallery id="albumTitle" /></perch:if>" id="<perch:gallery id="albumID" />"><img src="<perch:gallery id="albumimage" type="image" width="226" height="190" crop="true" />" alt="<perch:gallery id="albumTitle" />" height="190" width="226" /></a>
</perch:before>
<perch:if id="perch_item_index" match="neq" value="1">
    <a href="<perch:gallery id="main" />" title="<perch:if exists="extraInfo"><perch:gallery id="extraInfo" /><perch:else /><perch:gallery id="albumTitle" /></perch:if>" class="gallery-images"></a>
    </perch:if>
<perch:after>
    <h2><a href="<perch:gallery id="main" />" class="album-title"><perch:gallery id="albumTitle" /></a></h2>
    </li>
</perch:after>

Now, the page count works, but I can't get any pagination links to show... well, I can't figure out where to put them. Obviously not in image-list.html. It might be because it's late - am I being thick?

Lisa Morena

Lisa Morena 1 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are the values showing up in <perch:showall /> ?

Well the paging is working as the content is being split over multiple pages, but I don't have any pagination links. What am I looking for with showall? item-listing.html seems to have no idea that paging exists

I need the paging at the album level rather than image level.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You're looking for current_page, next_url etc

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

Nope, they don't show

Aha, think I may have sorted it with this after the rest on gallery.php:

$opts = array(
'template'=>'album-paging',
'paginate'=>true,
'count'=>20,
'sort'=>'albumID',
'sort-order'=>'DESC'
);
perch_gallery_album_listing($opts);

Yep, that did it! It is amazing what a weekend away from the computer can do for your brain!

Lisa, I used your code as a starting point and I was able to get it working, however, the pagination shows up as many times per page as there are albums. My gallery is structured very similarly to yours and I pasted the pagination code after the other code for the gallery, like you mentioned. Do you have any ideas what I might be doing wrong from your experience?

OK, so my gallery.php looks like this:

<ul id="albumdisplay">
<?php
$opts = array(
'skip-template'=>true,
'paginate'=>true,
'count'=>20,
'sort'=>'albumID',
'sort-order'=>'DESC'
);
$albums = perch_gallery_album_listing($opts);

foreach($albums as $album) {
$opts = array(
'template'=>'image-list.html'
);
perch_gallery_album($album['albumSlug'], $opts);
}
 ?> 
</ul>
 <?php $opts = array(
'template'=>'album-paging',
'paginate'=>true,
'count'=>20,
'sort'=>'albumID',
'sort-order'=>'DESC'
);
perch_gallery_album_listing($opts);
?>

and the album-paging template looks like this:

<perch:after> <perch:if exists="paging">
    <div class="paging">
      Page <perch:gallery id="current_page" /> of <perch:gallery id="number_of_pages" />
        <a href="<perch:gallery id="prev_url" encode="false" />" class="prev_url<perch:if exists="not_first_page"><perch:else /> hidden</perch:if>"><< Previous</a>
      <perch:content id="page_links" encode="false" type="hidden" />
      <a href="<perch:gallery id="next_url" encode="false" />" class="next_url<perch:if exists="not_last_page"><perch:else /> hidden</perch:if>">Next >></a>

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

Does that help you at all?

image-list.html looks like this:

<perch:before>
    <li class="gallery"><a href="<perch:gallery id="main" />" title="<perch:if exists="extraInfo"><perch:gallery id="extraInfo" /><perch:else /><perch:gallery id="albumTitle" /></perch:if>" id="<perch:gallery id="albumID" />"><img src="<perch:gallery id="albumimage" type="image" width="226" height="190" crop="true" />" alt="<perch:gallery id="albumTitle" />" height="190" width="226" /></a>
</perch:before>
<perch:if id="perch_item_index" match="neq" value="1">
    <a href="<perch:gallery id="main" />" title="<perch:if exists="extraInfo"><perch:gallery id="extraInfo" /><perch:else /><perch:gallery id="albumTitle" /></perch:if>" class="gallery-images"></a>
    </perch:if>
<perch:after>
    <h2><a href="<perch:gallery id="main" />" class="album-title"><perch:gallery id="albumTitle" /></a></h2>
    </li>
</perch:after>

I imagine you have just put the pagination in the wrong place??

Brilliant! I didn't have the pager code inside <perch:after> tags. That's what did it. Thank you for posting your code. This thread definitely helped me figure it out.

Glad I could help someone else out for a change :)