September 1, 2015 Development Tips

IMEDIA Blog | How To Create Previous & Next Links for Kentico Blog Posts

By: Laura Frese

A popular feature that many designers like to add in their Kentico CMS blogs are links allowing the user to easily navigate to the previous or next blog post. Unfortunately, there isn’t really a straightforward way describing how to do this within Kentico. In this post I will detail how you can use Kentico's Repeaters and Page Type Transformations to set up blog post previous and next links in just a few minutes!
 

Transformations

In the BlogPost page type create two transformations. One for the previous blog post, and one for the next one.

In these transformations, add your link to the previous or next post using the GetDocumentUrl() transformation method.

Blog Post Next Item Transformation

 

Repeaters

On your blog post page template you will need to add two repeaters. One for the previous link, and one for the next.

For the previous repeater add your usual settings & modify the following settings:

Page types: CMS.BlogPost
Select top N pages: 1
Where condition: BlogPostID = (select top 1 BlogPostID from CONTENT_BlogPost where BlogPostDate < '{%BlogPostDate%}' order by BlogPostDate desc)
Columns: DocumentUrlPath, SiteName, NodeAliasPath
Transformation: Select the transformation you made for the Previous blog post link

Adding the columns is recommended but not required. By limiting the number of columns returned, your request is more efficient.

For the next repeater add the same settings as above except:

Where condition: BlogPostID = (select top 1 BlogPostID from CONTENT_BlogPost where BlogPostDate > '{%BlogPostDate%}' order by BlogPostDate)
Transformation: Select the transformation you made for the Next blog post link

Blog post next link repeater


Voila! You now have previous and next links for your blog post page!

 

Share: