CMS Made Simple Forums
https://forum.cmsmadesimple.org/

Related CGBlog Articles
https://forum.cmsmadesimple.org/viewtopic.php?f=4&t=61944
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:

\$1:
{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}


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

\$1:
{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}


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.
\$1:
{CGBlog summarytemplate="related" category="$categories" number="6"}


Attachments:
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
http://www.phpbb.com/