CGBlog: Show related items on detail page

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
rick1980
New Member
New Member
Posts: 7
Joined: Fri Feb 04, 2011 7:15 pm

CGBlog: Show related items on detail page

Post 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}&nbsp;
 {/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
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am

Re: CGBlog: Show related items on detail page

Post 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>
rick1980
New Member
New Member
Posts: 7
Joined: Fri Feb 04, 2011 7:15 pm

Re: CGBlog: Show related items on detail page

Post by rick1980 »

Hi Nicmare,

Thank you for your quick response. It worked...thank you very much!

- Rick
rick1980
New Member
New Member
Posts: 7
Joined: Fri Feb 04, 2011 7:15 pm

Re: CGBlog: Show related items on detail page

Post 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
vinyl
Forum Members
Forum Members
Posts: 149
Joined: Mon Jul 13, 2009 8:18 pm

Re: CGBlog: Show related items on detail page

Post by vinyl »

I have the exact same issue. Only I also wonder how you make the comma separated list with categories.
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: CGBlog: Show related items on detail page

Post 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,"}
carasmo
Power Poster
Power Poster
Posts: 506
Joined: Thu Feb 08, 2007 6:11 pm

Re: CGBlog: Show related items on detail page

Post 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(',');

});

Post Reply

Return to “Modules/Add-Ons”