Edit Page List Pagination

Permalink 1 user found helpful
Hi,

Complete noob when it comes to php. I can find my way around with guidance but am struggling to get the pagination feature of the page list block to work the way I want.

The standard page list pagination has "Previous - 1 2 3 - Next" which always displays "Previous" and "Next" even on the first and last pages. I'd like to perform an if statement on the "Previous" and "Next" so that if there is no previous or next page, those pieces of text do not display.

My code for pagination is a slightly edited version of the core code:

<?php if ($paginate && $num > 0 && is_object($pl)): ?>
<div id="pagination">
<?php
$summary = $pl->getSummary();
if ($summary->pages > 1):
$paginator = $pl->getPagination();
?>
<span class="pagination-left"> <?php echo $paginator->getPrevious('Previous'); ?></span>
<span class="sfs-page"> <?php echo $paginator->getPages(); ?></span>
<span class="pagination-right"><?php echo $paginator->getNext('Next'); ?> </span>
<?php endif; ?>
</div>
<?php endif; ?>

Any help is greatly appreciated, I haven't managed to find a simple way to do this. Please remember I am a noob, so as simple an answer as possible please. Thanks in advance for the help!

 
bbeng89 replied on at Permalink Best Answer Reply
bbeng89
You can actually do:

if($paginator->hasPreviousPage()){
    //render previous button
}
//render pages
if($paginator->hasNextPage()){
    //render next button
}


Does that help answer your question?
alanstr84d replied on at Permalink Reply
Perfect! Thank you!