Show all news articles by the same author

By clicking on the author name, the visitor will be redirected to the news page listing only the articles created by the selected author.

Sometimes, a forum question motivates me to work something out simply because i find it a great idea!

In the News summary template, replace the the second {foreach} opening statement:

{foreach from=$items item=entry}

with this:

{foreach from=$items item=entry}
{if $smarty.get.selectedauthor!= ""}
    {capture assign="selectedauthor"}{$smarty.get.selectedauthor}{/capture}
{/if}
{if $selectedauthor}
    {capture assign="newsauthor"}{$entry->author}{/capture}
{/if}
{capture assign="newsitem"}

Then replace the author:

{$entry->author}

with this if you are using pretty url's: (NOTE: please replace "nieuwstest" with the alias of your news page!)

<a href="{$root_url}nieuwstest?selectedauthor={$entry->author}">{$entry->author}</a>

with this if you are NOT using pretty url's: (NOTE: please replace "nieuwstest" with the alias of your news page!)

<a href="{$root_url}index.php?page=nieuwstest&selectedauthor={$entry->author}">{$entry->author}</a>

Finally, replace the closing statement of that same "foreach":

{/foreach}

with:

{/capture}
{if $selectedauthor}
    {if $newsauthor === $selectedauthor}
        {$newsitem}
    {/if}
{else}
    {$newsitem}
{/if}
{/foreach}

You can use various techniques to hide the news sidebar (if you are using one) when the newspage is being shown. Just enter your preferred smarty code in your template to avoid showing the news items twice on the same page... You can find more information on this by searching the cmsms forum.

Greetings,
Manuel

Comments