Jump to content

Next page for pagination only


a-ok
 Share

Recommended Posts

Is there a way to return the next page in the pagination (as a link) only instead of rendering out the full pagination?

<?php
echo $results->renderPager(array(
    'nextItemLabel' => "Next",
    'previousItemLabel' => "Prev",
    'listMarkup' => "<ul class='MarkupPagerNav'>{out}</ul>",
    'itemMarkup' => "<li class='{class}'>{out}</li>",
    'linkMarkup' => "<a href='{url}'><span>{out}</span></a>"
));  

 

Link to comment
Share on other sites

7 minutes ago, oma said:

Have you tried:


<?php
echo $results->renderPager(array(
    'nextItemLabel' => "Next",
    'previousItemLabel' => "Prev",
    'listMarkup' => "",
    'itemMarkup' => "",
    'linkMarkup' => "<a href='{url}'><span>{out}</span></a>"
));

 

?

Link to comment
Share on other sites

As @Mike Rockett says, the quick and dirty way is to use CSS:

.MarkupPagerNav li { display:none; }
.MarkupPagerNav .MarkupPagerNavPrevious, .MarkupPagerNav .MarkupPagerNavNext { display:block; }

 

For a PHP solution, here's what I use for prev/next pagination of news summaries. I think it's based on some code shared here in the forums but I can't remember where.

In my case I wanted greyed-out prev/next links when on the first/last page.

<?php
$limit = 5;
$news = $pages->find("template=news_item, post_date<=today, limit=$limit, sort=sort");
$total_pages = ceil($news->getTotal() / $limit);

// output news summaries here

// pagination
if($total_pages > 1):
    $current_url = $page->url;
    if($input->urlSegmentsStr) $current_url .= $input->urlSegmentsStr . '/';
?>
    <div class="pagination">
        <div class="prev-page">
            <?php if($input->pageNum > 2): ?>
                <a rel="prev" href="<?= $current_url . $config->pageNumUrlPrefix . ($input->pageNum - 1) ?>">Prev page</a>
            <?php elseif($input->pageNum === 2): ?>
                <a rel="prev" href="<?= $current_url ?>">Prev page</a>
            <?php else: ?>
                Prev page
            <?php endif; ?>
        </div>
        <div class="centre-text">Page <?= $input->pageNum ?> of <?= $total_pages ?></div>
        <div class="next-page">
            <?php if($input->pageNum < $total_pages): ?>
                <a rel="next" href="<?= $current_url . $config->pageNumUrlPrefix . ($input->pageNum + 1) ?>">Next page</a>
            <?php else: ?>
                Next page
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

 

  • Like 4
Link to comment
Share on other sites

There's $page->next() and $page->prev() methods available that returns sibling pages matching an optional selector. You can use

$next = $page->next("published>$page->published, template=$page->template"); 
$prev = $page->prev("published<$page->published, template=$page->template");

Then you can echo their urls and build your own simple navigation.

See:

https://processwire.com/api/ref/page/
https://processwire.com/api/ref/page/next/
https://processwire.com/api/ref/page/prev/

  • Like 1
Link to comment
Share on other sites

  • 3 years later...

Hi @a-ok, i solved this with this code:

$news = $page->children("limit=5");
$pager = $modules->get('MarkupPagerNav');
// this is required in order for getUrl to work
// see https://processwire.com/api/ref/markup-pager-nav/get-u-r-l/
$pager->render($news);

$paginationMarkup = '';

if ($news->hasPrevPagination() || $news->hasNextPagination()) {
  $paginationMarkup .= '<ul>';

  if ($news->hasPrevPagination()) {
    $paginationMarkup .= "<li><a href='{$pager->getUrl($pager->pageNum - 1)}'>prev</a></li>";
  }

  if ($news->hasNextPagination()) {
    $paginationMarkup .= "<li><a href='{$pager->getUrl($pager->pageNum + 1)}'>next</a></li>";
  }

  $paginationMarkup .= '</ul>';
}

echo $paginationMarkup;

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...