Page 1 of 1
CGBlog: Show related items on detail page
Posted: Fri Feb 04, 2011 7:50 pm
by rick1980
Hello,
I have a problem with CGblog and I can't make it work
First I wanted to make the categories linkable. I did that with some help of this forum. See the following code (not working with internal urls of mod_rewrite unfortunatly).
Code: Select all
{if $entry->categories}
<div class="CGBlogDetailCategory">
{strip}
{foreach from=$entry->categories item='one_category'}
{capture assign='urlparam'}&category={$one_category.name}{/capture}
{cms_selflink page='categorie' urlparam=$urlparam text=$one_category.name|strtoupper}
{/foreach}
{/strip}
</div>
{/if}
</div>
Than I wanted to add releated topics based on category. I was able to that by adding the following code under the article.
Code: Select all
{CGBlog summarytemplate="RelatedItems" category=$one_category.name sortby="random"}
I have only one problem. The article you are reading also appears in the list of related topics. No my question is, how can I exclude the article you are reading.
Thank you in advance!
- Rick
Re: CGBlog: Show related items on detail page
Posted: Sat Feb 05, 2011 9:53 am
by nicmare
this is easy, i take my summary template code:
Code: Select all
{assign var='currentitem' value=$entry->id}
<ul>
{foreach from=$items item=entry}
{if $entry->id !=$currentitem}
<li>
<a href="{$entry->detail_url}">
{$entry->title|escape}
</a>
</li>
{/if}
{/foreach}
</ul>
Re: CGBlog: Show related items on detail page
Posted: Sat Feb 05, 2011 10:55 am
by rick1980
Hi Nicmare,
Thank you for your quick response. It worked...thank you very much!
- Rick
Re: CGBlog: Show related items on detail page
Posted: Mon Apr 18, 2011 1:18 pm
by rick1980
Hi,
I have another issues. It turns out that the releated items only works with one category. If you have multiple categories, it will only use the last one.
I looked into the array function to create a variable which adds a string with a comma seperated like cat1, cat2, cat3. But unfortunatly, it's not working. I cannot get strings into an array.
Can someone provide a solution for this?
Thank you,
Rick
Re: CGBlog: Show related items on detail page
Posted: Fri Jan 13, 2012 2:56 pm
by vinyl
I have the exact same issue. Only I also wonder how you make the comma separated list with categories.
Re: CGBlog: Show related items on detail page
Posted: Sun Jun 17, 2012 6:15 am
by carasmo
on detail page latest CBblog module
Code: Select all
{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}
then at the bottom of the article:
Code: Select all
{CGBlog summarytemplate="related" category="$categories"}
Assumes summary template "related" with the same code as listed from nicmare.
Don't worry about the trailing comma, it still works with cat1, cat3, cat5,
it's the equivalent of this:
Code: Select all
{CGBlog summarytemplate="related" category="cat2,cat3,cat5,"}
Re: CGBlog: Show related items on detail page
Posted: Sun Jun 17, 2012 6:18 am
by carasmo
latest cgblog, linkable categories on summary or detail page, pretty urls:
Code: Select all
{if $entry->categories}
<div class="categories">filed under: <ul>{strip}
{foreach from=$entry->categories item='one_category'}
{foreach from=$categories item='one'}
{if $one_category.name == $one.name}
<li> <a href="{$one.url}" title="{$one.name}">{$one.name}</a></li>
{/if}
{/foreach}
{/foreach}
{/strip}
</ul></div>
{/if}
I have some jquery to add a comma between each one but not the last:
Code: Select all
$(document).ready(function() {
// Add comma to categories unless there is only one and except the :last-child ******//
$('div.categories ul li').not(':last-child').append(',');
});