Filter news items in search by category and user login
Posted: Thu Sep 04, 2014 6:25 pm
Hi,
I've been trying to work out how to filter news items included in search results by category and user login state.
I finally found a rather simple solution, so I thought I'd share it here.
Create a summary template in the news module, which only creates a smarty array with the chosen information. In my case this was the id's of news items for public access. So, something like this:
Then calls the news module in the beginning of your search template:
{news summarytemplate="show_in_search" category="public"}
and filter:
This method could be easily expanded to filter for different user groups etc.
Hope this helps.
I've been trying to work out how to filter news items included in search results by category and user login state.
I finally found a rather simple solution, so I thought I'd share it here.
Create a summary template in the news module, which only creates a smarty array with the chosen information. In my case this was the id's of news items for public access. So, something like this:
Code: Select all
{foreach from=$items item=entry}
{$publicnews[]=$entry->id}
{/foreach}
{news summarytemplate="show_in_search" category="public"}
and filter:
Code: Select all
{if ccUser::loggedin()}
<li> {$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a></li>
{else}
{if $entry->module == 'News' && $entry->modulerecord|in_array:$publicnews}
<li> {$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a> </li>
{/if}
{/if}
Hope this helps.