Mecha CMS

Code snippet collection for developers.

Next and Previous Pagination Links with the Post Title

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>