I understand how to show only certain categories in the News module... category="category1, category2"
Is it possible to exclude a category? I am using a category for a specific function and do not wish it to show up on the 'news' page. And, to make things easier for editors that may add categories, I'd like to just exclude the one that shouldn't be included on the news page instead of relying on the editors to add their new category to category paramater in the News smarty tag.
Thanks!
Exclude one news category
Exclude one news category
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Re: Exclude one news category
hello,
why don't you just call the category's you only want to display??
why don't you just call the category's you only want to display??
-
- Forum Members
- Posts: 103
- Joined: Fri Nov 28, 2008 11:26 am
Re: Exclude one news category
Hi,
I also have this need. We're adding news categories all the time, and so its not really viable to be updating the pages where theyre ALL called just to exclude a single category. Is there something whereby I can just write
or something like that? (this would show all categories except 'mysecretcategory')
Thanks.
I also have this need. We're adding news categories all the time, and so its not really viable to be updating the pages where theyre ALL called just to exclude a single category. Is there something whereby I can just write
Code: Select all
{news exclude='mysecretcategory'}
Thanks.
Last edited by beherenow_uk on Tue Dec 07, 2010 10:59 am, edited 1 time in total.
Re: Exclude one news category
x3
Time to add a feature request for the News module in the Forge.
Time to add a feature request for the News module in the Forge.
Re: Exclude one news category
Peciura helped me on same problem when i was working on my Blog so i think the code could be changed for News to.
Create a UDT, mine is named blogcat:
Now use this call:
{blogcat exclude='Your Category' assign='cat_list'}{CGBlog category=$cat_list summarytemplate='your Template'}
Create a UDT, mine is named blogcat:
Code: Select all
/**
* Get CGBlog category comma separated list.
*
* @params string $params['exclude'] comma separated list of categories to be excluded.
* @params string $params['noslashes'] Add slashes from category names ( added for better DB compatibility).
* @params string $params['assign'] Assign value to.
*
*/
$cat_delim = ',';
$return = '';
$cat_array = array();
$cat_exclude = array();
$db = cmsms()->GetDB();
$query = "SELECT `name` FROM ".cms_db_prefix()."module_cgblog_categories ORDER BY sort_order";
$dbresult = $db->Execute($query);
while ($dbresult && $row = $dbresult->FetchRow())
{
if(empty($params['noslashes'])){
$row['name'] = addslashes($row['name']);
}
$cat_array[$row['name']] = $row['name'];
}
if (!empty($params['exclude'])){
$cat_exclude = explode($cat_delim, trim($params['exclude']));
foreach($cat_exclude as $name){
$name = trim($name);
if (isset($cat_array[$name])){
unset($cat_array[$name]);
}
}
}
$return = implode($cat_delim, $cat_array);
if(!empty($params['assign'])){
$smarty = cmsms()->GetSmarty();
$smarty->assign(trim($params['assign']), $return);
}
else{
return $return;
}
{blogcat exclude='Your Category' assign='cat_list'}{CGBlog category=$cat_list summarytemplate='your Template'}
Last edited by uniqu3 on Tue Dec 07, 2010 4:33 pm, edited 1 time in total.
Re: Exclude one news category
Another way of doing it:
1.
Go to Content->News->Browse Category Templates
Create a new template, (I called it Test), with the following content:
2.
Go to Extensions->User Defined Tags
Create a new UDT, (called Remove), with the following contents:
3.
In the page where you want the news insert something like this:
This will show all news except from the categories General and Major.
If you always want to exclude the same category you could simplify things by removing it with smarty logic already in the browsecat template and skip the UDT.
But the UDT method is more flexible.
Edit:
Note that this method does not correctly handle sub categories.
If you need those it must be slightly modified.
1.
Go to Content->News->Browse Category Templates
Create a new template, (I called it Test), with the following content:
Code: Select all
{if $count > 0}
{foreach from=$cats item=node}
{$node.news_category_name},
{/foreach}
{/if}
Go to Extensions->User Defined Tags
Create a new UDT, (called Remove), with the following contents:
Code: Select all
$remove = explode( ',', trim( $params['remove']));
$input = explode( ',', trim( trim( $params['input']), ','));
$input = array_map( trim, $input);
echo implode( ',', array_diff( $input, $remove));
In the page where you want the news insert something like this:
Code: Select all
{capture assign="all_cats"}{news action="browsecat" browsecattemplate="Test"}{/capture}
{capture assign="cats"}{Remove input=$all_cats remove="General,Major"}{/capture}
{news category=$cats}
If you always want to exclude the same category you could simplify things by removing it with smarty logic already in the browsecat template and skip the UDT.
But the UDT method is more flexible.
Edit:
Note that this method does not correctly handle sub categories.
If you need those it must be slightly modified.
Last edited by andershz on Wed Dec 08, 2010 7:49 am, edited 1 time in total.