Mecha CMS

Mecha CMS blog and documentation.

Add Post Title to the Next and Previous Pagination Link

Updated: Sunday, 07 August 2016

How to add post title in the next and previous link on the article page?

<nav class="blog-pager">
  <span class="blog-pager-prev">
  <?php

  if( ! empty($pager->prev->anchor)) {
      $post = Get::articleAnchor(File::B($pager->prev->url));
      echo '<a href="' . $post->url . '" rel="prev"><b>' . $speak->prev . ':</b> ' . $post->title . '</a>';
  }

  ?>
  </span>
  <span class="blog-pager-next">
  <?php

  if( ! empty($pager->next->anchor)) {
      $post = Get::articleAnchor(File::B($pager->next->url));
      echo '<a href="' . $post->url . '" rel="next"><b>' . $speak->next . ':</b> ' . $post->title . '</a>';
  }

  ?>
  </span>
</nav>

Use the code above as a replacement for the next/previous pagination in article.php.

Donation and Email Subscription