Page 1 of 1

News Module - Category and Article Name Menu

Posted: Wed Jul 07, 2010 9:10 am
by zestmark
Hi All,

I wonder if anyone can help me with a little thing I am trying to do for part of a website I have created which I am now extending. Basically, instead of using a menu of pages, I would like to create a menu from news articles and categories for example:

Category 1
            News Article 1
            News Article 2
            News Article 3

Category 2
            News Article 4
            News Article 5
            News Article 6

Category 3
            News Article 7
            News Article 8
            News Article 9

At the moment, I have tried to add the summary template to the browse category template wit no success as I am getting the same articles appear within each of the categories, for example:

Category 1
            News Article 1
            News Article 2
            News Article 3

Category 2
            News Article 1
            News Article 2
            News Article 3

Here is the code I have been using:

Code: Select all

{if $count > 0}
<ul class="list1">
{foreach from=$cats item=node}
{if $node.depth > $node.prevdepth}
{repeat string="<ul>" times=$node.depth-$node.prevdepth}
{elseif $node.depth < $node.prevdepth}
{repeat string="</li></ul>" times=$node.prevdepth-$node.depth}
</li>
{elseif $node.index > 0}</li>
{/if}
<li class="newscategory">
{if $node.count > 0}
	<a href="{$node.url}">{$node.news_category_name}</a>

<!-- Start News Display Template -->
{foreach from=$items item=entry}
<div class="NewsSummary">

<div class="NewsSummaryLink">
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a>
</div>

</div>
{/foreach}
<!-- End News Display Template -->

{else}<span>{$node.news_category_name} (0)</span>{/if}
{/foreach}
{repeat string="</li></ul>" times=$node.depth-1}</li>
</ul>
{/if}
If anyone can help me with this, I will be eternally grateful. I love CMSMS and we use it in our company and all of our clients say to us how great a system it is so bravo! Keep up the good work!

Thanks.

Mark

Re: News Module - Category and Article Name Menu

Posted: Thu Feb 03, 2011 4:34 pm
by kerryshamblin
Wondering if you figured this out? I'm having the same results with a simplified template that looks like this:

Code: Select all

<!-- Start News Display Template -->
<div class="NewsSummary">
{foreach from=$cats item=node}

<h2>{$node.news_category_name}</h2>

{foreach from=$items item=entry}
     
<p><strong>{$entry->title|cms_escape}:</strong>
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{eval var=$entry->summary}</a></p>

{/foreach}

{/foreach}
</div>

<!-- End News Display Template -->
I wish I knew Smarty better. I've been stabbing around, but unsuccessfully.

What I would like is to display each category and then all of the articles within the category with my Summary Template. Thanks in advance for the help!

Re: News Module - Category and Article Name Menu

Posted: Thu Feb 03, 2011 7:58 pm
by spcherub
@kerryshamblin - The problem with your code is that while your outer loop is for the categories, the inner loop loops through ALL entries, not just the entries in the current category of the outer loop. One (hack) way to fix this, is to add an if condition so only the entries whose category matches the category in the outer loop will print. I don't have access to CMSMS right now to find out the smarty variable, but in pseudo-code it would look something like this:

Code: Select all

<!-- Start News Display Template -->
<div class="NewsSummary">
{foreach from=$cats item=node}

<h2>{$node.news_category_name}</h2>

{foreach from=$items item=entry}

{if $entry->category_name == $node.news_category_name}

<p><strong>{$entry->title|cms_escape}:</strong>
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{eval var=$entry->summary}</a></p>

{/if}

{/foreach}

{/foreach}
</div>

<!-- End News Display Template -->

Re: News Module - Category and Article Name Menu

Posted: Thu Feb 03, 2011 8:15 pm
by kerryshamblin
Thanks, @spcherub! That's the direction I was heading, but maybe my problem is that I can't find the smarty variables for News. Can you please tell me where to look?

Re: News Module - Category and Article Name Menu

Posted: Thu Feb 03, 2011 8:22 pm
by spcherub
Kerry - I just checked and the way to get category for an entry is $entry->category. My amended code is below. I have not tried it out myself, but it should work in principle. Try it out and post your results here.

Code: Select all

<!-- Start News Display Template -->
<div class="NewsSummary">
{foreach from=$cats item=node}

<h2>{$node.news_category_name}</h2>

{foreach from=$items item=entry}

{if $entry->category == $node.news_category_name}
<p><strong>{$entry->title|cms_escape}:</strong>
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{eval var=$entry->summary}</a></p>
{/if}

{/foreach}

{/foreach}
</div>

<!-- End News Display Template -->

Re: News Module - Category and Article Name Menu

Posted: Thu Feb 03, 2011 8:27 pm
by kerryshamblin
Worked like a charm! Thanks. Can we mark this solved?

Re: News Module - Category and Article Name Menu

Posted: Thu Feb 03, 2011 8:29 pm
by Dr.CSS
You can mark your post as solved by hitting the green checkmark in post...

Re: News Module - Category and Article Name Menu

Posted: Thu Feb 03, 2011 11:58 pm
by kerryshamblin
So, that's a no, then. It's up to zestmark. Thanks for the help spcherub!