Hi Guys
I have 2 news items but I like to show only the Sports news in a page. Currently, I am getting this when I use the browse category template:
General
Current News
Sports
- Swimming
- Running
- Cycling
What I'm trying to do it to show only the Sports Category and its content like the following:
Swimming
- Title of Story One
- Title of Story Two
- Title of Story Three
Running
- Title of Story One
- Title of Story Two
- Title of Story Three
Cycling
- Title of Story One
- Title of Story Two
How can I achieve this? Thanks
[Solved] News: Show Title in Child Categories In Browser
[Solved] News: Show Title in Child Categories In Browser
Last edited by dinmix on Wed May 01, 2013 4:37 pm, edited 2 times in total.
-
oliverseddon
- Forum Members

- Posts: 89
- Joined: Thu Aug 21, 2008 11:47 am
Re: News: Show Title in Child Categories In Browse Template
Hi,
I would suggest using a regular Summary template rather than the browsecat option. Then do something like this:
I would suggest using a regular Summary template rather than the browsecat option. Then do something like this:
Code: Select all
{assign var='currentCat' value=''}
{foreach from=$items item=entry}
{if $entry->category == 'Swimming'}
{if $currentCat != $entry->category}<h2>{$entry->category}</h2>{/if}
{assign var='currentCat' value=$entry->category}
<div class="NewsSummary">
{if $entry->postdate}
<div class="NewsSummaryPostdate">
{$entry->postdate|cms_date_format}
</div>
{/if}
<div class="NewsSummaryLink">
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a>
</div>
{if $entry->author}
<div class="NewsSummaryAuthor">
{$author_label} {$entry->author}
</div>
{/if}
{if $entry->summary}
<div class="NewsSummarySummary">
{eval var=$entry->summary}
</div>
<div class="NewsSummaryMorelink">
[{$entry->morelink}]
</div>
{else if $entry->content}
<div class="NewsSummaryContent">
{eval var=$entry->content}
</div>
{/if}
{if isset($entry->extra)}
<div class="NewsSummaryExtra">
{eval var=$entry->extra}
{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
</div>
{/if}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="NewsSummaryField">
{if $field->type == 'file'}
<img src="{$entry->file_location}/{$field->value}"/>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
</div>
{else if $entry->category == 'Running'}
{if $currentCat != $entry->category}<h2>{$entry->category}</h2>{/if}
{assign var='currentCat' value=$entry->category}
<div class="NewsSummary">
{if $entry->postdate}
<div class="NewsSummaryPostdate">
{$entry->postdate|cms_date_format}
</div>
{/if}
<div class="NewsSummaryLink">
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a>
</div>
{if $entry->author}
<div class="NewsSummaryAuthor">
{$author_label} {$entry->author}
</div>
{/if}
{if $entry->summary}
<div class="NewsSummarySummary">
{eval var=$entry->summary}
</div>
<div class="NewsSummaryMorelink">
[{$entry->morelink}]
</div>
{else if $entry->content}
<div class="NewsSummaryContent">
{eval var=$entry->content}
</div>
{/if}
{if isset($entry->extra)}
<div class="NewsSummaryExtra">
{eval var=$entry->extra}
{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
</div>
{/if}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="NewsSummaryField">
{if $field->type == 'file'}
<img src="{$entry->file_location}/{$field->value}"/>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
</div>
{else if $entry->category == 'Cycling'}
{if $currentCat != $entry->category}<h2>{$entry->category}</h2>{/if}
{assign var='currentCat' value=$entry->category}
<div class="NewsSummary">
{if $entry->postdate}
<div class="NewsSummaryPostdate">
{$entry->postdate|cms_date_format}
</div>
{/if}
<div class="NewsSummaryLink">
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a>
</div>
{if $entry->author}
<div class="NewsSummaryAuthor">
{$author_label} {$entry->author}
</div>
{/if}
{if $entry->summary}
<div class="NewsSummarySummary">
{eval var=$entry->summary}
</div>
<div class="NewsSummaryMorelink">
[{$entry->morelink}]
</div>
{else if $entry->content}
<div class="NewsSummaryContent">
{eval var=$entry->content}
</div>
{/if}
{if isset($entry->extra)}
<div class="NewsSummaryExtra">
{eval var=$entry->extra}
{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
</div>
{/if}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="NewsSummaryField">
{if $field->type == 'file'}
<img src="{$entry->file_location}/{$field->value}"/>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
</div>
{/if}
{/foreach}
Re: News: Show Title in Child Categories In Browse Template
Excellent! Thank you very much Oliver. The result is exactly what I want but with this I have to add the category name in the template every time I add new one. Is there a way to make automate this similar to the browsecat template?
-
oliverseddon
- Forum Members

- Posts: 89
- Joined: Thu Aug 21, 2008 11:47 am
Re: News: Show Title in Child Categories In Browse Template
Looks like this would do it:
Then your {news} call would need to look something like:
Code: Select all
{assign var='currentCat' value=''}
{assign var='open' value=false}
{foreach from=$items item=entry}
{if $currentCat != $entry->category}
{if $open}</div>{/if}
<h2 class="category-title">{$entry->category}</h2>
<div class="items">
{assign var='currentCat' value=$entry->category}
{assign var='open' value=true}
{/if}
<div class="NewsSummary">
{if $entry->postdate}
<div class="NewsSummaryPostdate">
{$entry->postdate|cms_date_format}
</div>
{/if}
<div class="NewsSummaryLink">
<a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a>
</div>
{if $entry->author}
<div class="NewsSummaryAuthor">
{$author_label} {$entry->author}
</div>
{/if}
{if $entry->summary}
<div class="NewsSummarySummary">
{eval var=$entry->summary}
</div>
<div class="NewsSummaryMorelink">
[{$entry->morelink}]
</div>
{else if $entry->content}
<div class="NewsSummaryContent">
{eval var=$entry->content}
</div>
{/if}
{if isset($entry->extra)}
<div class="NewsSummaryExtra">
{eval var=$entry->extra}
{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
</div>
{/if}
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="NewsSummaryField">
{if $field->type == 'file'}
<img src="{$entry->file_location}/{$field->value}"/>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
</div>
{/foreach}
{if $open}</div>{/if}
Code: Select all
{news sortby='news_category' category='Sport*'}Re: News: Show Title in Child Categories In Browse Template
Thank you so much! Exactly what I was looking for and it work like a charm. I've have spend two days trying to do this and you did that in like a minute. You are a life saver! Thank you! Thank you! 
-
oliverseddon
- Forum Members

- Posts: 89
- Joined: Thu Aug 21, 2008 11:47 am
Re: [Solved] News: Show Title in Child Categories In Browser
No problem, glad to help. Some inspiration was taken from the ListIt2 module's template.
Thanks
Oliver
Thanks
Oliver
