Blog Related Articles/Posts

Blog Related articles can be listed based on Content Tags.

This article describes how to do this and provides examples within the Aurora Demo Front-end Templates.

Overview

This article makes use of the contentBlogFind function described in the Blog Functions article to collect a list of Blogs considered to be 'Related' to the provided blog (which is usually the blog being viewed at the time). For a working example of the Related Articles implementation, pleas see the example.com/blog/related_articles.tpl.html Aurora Front-end Template or view the page below:

https://demo.auroracommerce.com/blog/

🚧

The examples provided in this document and the supporting Aurora Demo Example Templates are for illustrative purposes and reference only.

Example Front-end Template Code

The following is a very basic snippet of code that can be dropped into any template where you have access to a Blogs list of Tags.

👍

You could simply provide your own list of tags if you wish to list related articles in a particular section of your website rather than on a particular Blog article.

{* Build a comma-separated list of tags to search for (This particular code works in the 'blog/single.tpl.html' template, but you can build your list of tags however you please). *}
{foreach from=$page.tags item="tag"}
	{capture assign="related_tags"}{$related_tags},{$tag.name}{/capture}
{/foreach}
 
{* Search for all articles featuring any one (or more) of these tags, excluding the current content item. *}
{contentBlogFind tags=$related_tags exclude_content_id=$page.id item="related_articles"}
 
{* Display the articles found. *}
{if $related_articles}
	<h3>Related Articles</h3>
	{foreach from=$related_articles item="related_article"}
		<div class="template_blog_related_article">
			<a href="{$related_article.permalink}">{$related_article.title}</a> by {$related_article.author.firstname} {$related_article.author.lastname}
			{$related_article.page_introduction}
		</div>
	{/foreach}
{/if}

Using Ajax

It is possible to retrieve the 'related' articles in both HTML and JSON format using the Blog Ajax's method. To do this, simply make the request providing the following example parameters to instruct Aurora to both return only the 'related' articles in addition to optionally using the same 'related articles' template described in the Overview section of this article.

  • return_format: "HTML"
  • return_template: "blog/related_articles.tpl.html"
  • tags: "tag,tag,tag"

🚧

The value referenced as "tag,tag,tag" should be replaced with your own comma-separated list of tags to search for related articles by.

Related Aurora Demo Example Files
example.com/blog/related_articles.tpl.html
example.com/_js/blog.js