How to Create "Show Previous/Next Blog Post" Links


I’m new to this forum and quite new to Pulse.

I am looking for a PHP script / block that creates a simple paging for individual Pulse blog posts. I know a bit of HTML and CSS, but not much about PHP, so I can’t do it myself.

What I need are just two links/buttons, “Previous Post” and “Next Post”. If there are no more previous/next posts, the respective link/button should be disabled or removed.

Any help or suggestions would be appreciated.



Hello Frank, there are ‘older’ and ‘newer’-buttons that appear after a certain number of blogposts. That depends on what you set in config.php. It is set to 5, but you van easily change that.

1 Like

Thanks, Mary. I already recognized these buttons. But I am looking for similar buttons that only appear on pages containing a single post, so that the reader can continuously read all posts.

Moreover, if such links are present, Safari Reader Mode seems to automatically concatenate all posts into a single page.

Aaaah, so I guess you have to move this to the ‘wishlist’ section? :relaxed:

I meanwhile managed to do it myself. For anybody who is interested, here’s the code (but beware, it’s just amateur programming :grin:). You’ll have to edit the variables to fit your needs.

$blog_prefix = "blog"; //prefix as entered in config.php

if(isset($_GET[$blog_prefix])) {
    $pulse_path = "../pulse/"; //relative path to Pulse folder
    $post_page = "/post/"; //absolute path to individual blog posts
    $prev_post_string = "Previous"; //link text
    $next_post_string = "Next"; //link text

    if (is_numeric($_GET[$blog_prefix])) {
        $current_post_id = $_GET[$blog_prefix];

    $all_blog_files = glob($pulse_path . "content/blog/*.txt");

    $total_pages = count($all_blog_files);
    $prev_post_id = $current_post_id - 1;
    $next_post_id = $current_post_id + 1;
    echo "<div class='blog_paging'>";

    if ($prev_post_id >= 1) {
        echo "<a class='prev_post_link' href='" . $post_page . "?" . $blog_prefix . "=" . $prev_post_id . "'>" . $prev_post_string . "</a>";

    if ($next_post_id <= $total_pages) {
        echo "<a class='next_post_link' href='" . $post_page . "?" . $blog_prefix . "=" . $next_post_id . "'>" . $next_post_string . "</a>";

    echo "</div>";

I used the following CSS to style it:

.blog_paging {
  margin-bottom: 2.5rem;

/* Clearfix */
.blog_paging:after {
  content: "";
  display: block;
  clear: both;

.blog_paging .prev_post_link {
  float: left;

.blog_paging .next_post_link {
  float: right;

.blog_paging .prev_post_link:before,
.blog_paging .next_post_link:after {
    font-family: FontAwesome;
    display: inline-block;
    font-weight: normal;
    font-style: normal;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-decoration: none;

.blog_paging .prev_post_link:before {
  content: "\f0d9";
  margin-right: .3em;

.blog_paging .next_post_link:after {
  content: "\f0da";
  margin-left: .3em;

.blog_paging .prev_post_link:before:hover,
.blog_paging .prev_post_link:before:focus,
.blog_paging .next_post_link:after:hover,
.blog_paging .next_post_link:after:focus {
  text-decoration: none;

Maybe I should have read this thread before I started doing the same :slight_smile:
Anyways, here is a different solution. It uses the same link names as the blog to avoid duplicate content.

Pulse 4.6
Find lines 78-80

		if ($disqus_comments == true){include('inc/plugins/disqus.php');}
		echo "</div>";

Replace with

		if ($disqus_comments == true){include('inc/plugins/disqus.php');}
		echo "</div>";
    if (($get_id > 1) && ($page != 'home')) { 
    $opennext         = fopen($all_blog_files[$get_id-1][0] , "r"); 
    $datanext         = fread($opennext, filesize($all_blog_files[$get_id-1][0])); fclose($opennext);
    $linesnext        = explode("\n", $datanext);
    $titlenext        = $linesnext[0];
    $url_titlenext    = $all_blog_files[$get_id-1][1].'-'.str_replace(" ", "-", $titlenext);    
    echo "<a class='older' href=\"".$blog_prefix."-".strtolower($url_titlenext)."\">Previous</a>"; 
    if ($get_id < $amount_of_posts) { 
    $openprev         = fopen($all_blog_files[$get_id+1][0] , "r"); 
    $dataprev         = fread($openprev, filesize($all_blog_files[$get_id+1][0])); fclose($openprev);
    $linesprev        = explode("\n", $dataprev);
    $titleprev        = $linesprev[0];
    $url_titleprev    = $all_blog_files[$get_id+1][1].'-'.str_replace(" ", "-", $titleprev);
    echo "<a class='newer' href=\"".$blog_prefix."-".strtolower($url_titleprev)."\">Next</a>";  

Find a demo here:

1 Like

Thanks, @dirk, for your help and your efforts. I haven’t read this post until today… :slight_smile:

1 Like

This topic was automatically closed after 11 hours. New replies are no longer allowed.