Add Next and Previous Posts to Carbonate Homepage

by Josh Koop | Last Updated: February 13, 2021
As an Amazon Associate we earn from qualifying purchases made on our website. If you make a purchase through links from this website, we may get a small share of the sale from Amazon and other similar affiliate programs. You can read our complete disclaimer information for more details.

While making this site have better functionality to see more posts and scroll I built in the ability to scroll through the archives to new and older posts which isn’t included in Carbonate by default.

These instructions will help you add this to your home index page in Carbonate to allow scrolling through more than the original 9 or 12 posts.

You will need to find and remove the code below to strip away the limit of 12 posts that are returned by the search and allow the function of next posts to work as intended:

<?php $args = array('posts_per_page'  => 12, 'post_type' => 'post', 'post_status' => 'publish'); ?>
        <?php $posts = get_posts($args); ?>

Once this is deleted you will need to find the area of the index.php as you will need to add code after this line:

<?php } ?>

After this line you need to add the code below which will add two clickable buttons with “See More Posts” and “See Previous Posts”.

<div class="container py-5 prev-next">
	<div class="white-bg btn border next-left"><?php next_posts_link( 'See More Posts' ); ?></div><div class="white-bg btn border next-right"><?php previous_posts_link( 'See Previous Posts' ); ?>
	</div>
</div>

What this does is basically build two buttons (the class btn) that call the next posts or previous posts.

You can change their colors by altering the white-bg to whichever background colors you have built or the standards in styles.css.

I added the following CSS for this site and it can be a starting point for you to begin customizing your implementation:

.prev-next {
    text-align: center;
    max-width: 75%;
}

.next-right {
    float: left;
}

.next-left {
    float: right;
}
I love technology, I have plenty of technical side experience but never really thought of blogging as a way to earn an income. With everything that has gone on in the last couple years and the instability of the job markets I started to learn how to blog and build affiliate niche sites to add more income channels to give me the chance to break free from the financial chains that bind me and find real freedom!