News Module - Category and Article Name Menu

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
zestmark
Forum Members
Forum Members
Posts: 10
Joined: Thu May 21, 2009 1:39 pm

News Module - Category and Article Name Menu

Post 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
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: News Module - Category and Article Name Menu

Post 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!
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: News Module - Category and Article Name Menu

Post 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 -->
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: News Module - Category and Article Name Menu

Post 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?
spcherub
Power Poster
Power Poster
Posts: 402
Joined: Fri Jun 06, 2008 5:54 pm

Re: News Module - Category and Article Name Menu

Post 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 -->
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: News Module - Category and Article Name Menu

Post by kerryshamblin »

Worked like a charm! Thanks. Can we mark this solved?
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: News Module - Category and Article Name Menu

Post by Dr.CSS »

You can mark your post as solved by hitting the green checkmark in post...
User avatar
kerryshamblin
Forum Members
Forum Members
Posts: 87
Joined: Wed Apr 14, 2010 5:21 pm

Re: News Module - Category and Article Name Menu

Post by kerryshamblin »

So, that's a no, then. It's up to zestmark. Thanks for the help spcherub!
Post Reply

Return to “Modules/Add-Ons”