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:
Code: Select all
{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}
{foreach from=$items item=entry}
{if $entry->id !=$currentitem}
<li>
<a href="{$entry->detail_url}">
{$entry->title|escape}
</a>
</li>
{/if}
{/foreach}
{assign var='related2' value=0}
{foreach from=$items item=entry}
{if $entry->id !=$currentitem and $related2 == 0}
</ul></section>
{assign var='related2' value=1}{/if}
{/foreach}
Code: Select all
{strip}{capture assign="categories"}{foreach from=$entry->categories item='one_category'}{foreach from=$categories item='one'}{if $one_category.name == $one.name}{$one.name},{/if}{/foreach}{/foreach}{/capture}{/strip}
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.
Code: Select all
{CGBlog summarytemplate="related" category="$categories" number="6"}