Show all news articles by the same author

Mon. 13. February 2012 Smarty CMSMS General Manuel
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



Article was created by Manuel

Manuel

I'm a cmsms addict from Belgium. I had to check my forum profile but it has apparently started in 2007 :)

« Back to Articles

Comments

Categories

Archive

From Twitter

I love CMSMS

Designed and developed by idea arts. I do this! © Copyright 2010-2013

Go back to Top