Filter news items in search by category and user login

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
lholsti
New Member
New Member
Posts: 5
Joined: Tue Nov 09, 2010 6:19 pm

Filter news items in search by category and user login

Post by lholsti »

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:

Code: Select all

{foreach from=$items item=entry}
  {$publicnews[]=$entry->id}
{/foreach}
Then calls the news module in the beginning of your search template:
{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}
This method could be easily expanded to filter for different user groups etc.

Hope this helps.
Post Reply

Return to “Tips and Tricks”