Mecha CMS

Mecha CMS blog and documentation.

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 = LOT . DS . '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 = LOT . DS . '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>

9 Comments

  • Taufik Nurrohman

  • Taufik Nurrohman

  • Taufik Nurrohman

  • Taufik Nurrohman

  • Taufik Nurrohman

  • Taufik Nurrohman

  • 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.

  • Taufik Nurrohman