CMS Made Simple Forums

Related CGBlog Articles
Page 1 of 1

Author:  carasmo [ Thu Jul 12, 2012 7:05 pm ]
Post subject:  Related CGBlog Articles

In the footer of my blog posts, on the detail page I have listed the related articles based on help from this forum to not print out the current article in other places on my site I also have smarty stuff based on help from this forum, particularly Robert Campbell, so combining some stuff, this here trick does the following:

Puts a related list of articles at the bottom of your blog posts based on categories that the post is assigned to, multiple categories, AND if there are none, the header "Related Articles" and the accompanying html holding those links is not printed out.

First make a SUMMARY CBBlog template called "related" in this example:

{assign var='currentitem' value=$entry->id}
{assign var='related1' value=0}
{foreach from=$items item=entry}
{if $entry->id !=$currentitem and $related1 == 0}
<section class="related clearfix"><h5>Related Articles</h5>
<ul>{assign var='related1' value=1}{/if}

{foreach from=$items item=entry}
{if $entry->id !=$currentitem}
         <a href="{$entry->detail_url}">

{assign var='related2' value=0}
{foreach from=$items item=entry}
{if $entry->id !=$currentitem and $related2 == 0}
{assign var='related2' value=1}{/if}

Next, in your DETAIL CGBlog template you will need to do put the following:

{strip}{capture assign="categories"}{foreach from=$entry->categories item='one_category'}{foreach from=$categories item='one'}{if $ == $}{$},{/if}{/foreach}{/foreach}{/capture}{/strip}

This captures the categories for that blog Post and must come before the call to the related categories summary template

Then in the bottom of your blog DETAIL page as well, where you want the related categories to show up (if there are any), then paste the following. You will get a result like the screen shot (after applying your own css) IF there are related articles, but nothing if there are none.
{CGBlog summarytemplate="related" category="$categories" number="6"}

Screen Shot 2012-07-12 at 2.58.06 PM.png
Screen Shot 2012-07-12 at 2.58.06 PM.png [ 91.89 KiB | Viewed 3230 times ]

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group