Snippet · Mecha CMS

Code snippet collection for developers.

Next and Previous Pagination Links with the Post Title

Author: Taufik Nurrohman · 624 Views

Tweet

How to add post title to the next and previous link of the item page.

Replace the default pager that you see in page.php file with this:

<nav style="overflow:hidden;">
  <?php if ($s = $pager->previous): ?>
    <?php $s = PAGE . DS . str_replace($url . '/', "", $s) . '.page'; ?>
    <span style="float:left;">
      <?php echo $pager->previous(Elevator::WEST . ' ' . Page::open($s)->get('title')); ?>
    </span>
  <?php endif; ?>
  <?php if ($s = $pager->next): ?>
    <?php $s = PAGE . DS . str_replace($url . '/', "", $s) . '.page'; ?>
    <span style="float:right;">
      <?php echo $pager->next(Page::open($s)->get('title') . ' ' . Elevator::EAST); ?>
    </span>
  <?php endif; ?>
</nav>

The default pager usually looks like this:

<nav><?php echo $pager; ?></nav>

2 Comments

  • Alexander Liebrecht

    Hi @Tovic,

    I would like to test your comments again. This navigation between the pages I have already installed. Thanks for this opportunity. The reader of the blog will then thank me.

    • Taufik Nurrohman

      You are welcome.