Adding previous and next links to the modules detail pages
Previous article Next articleThis tutorial demonstrates the power and simplicity of Smarty template code by using it to add previous and next buttons to the CMS Made Simple™ News module without any UDT.
How to use
Create a new News summary template, named "prev_next_links", with the content:
{capture append='allIDs'}{$the_entry->id}{/capture}
{capture append='allURLs'}{$the_entry->moreurl}{/capture}
{/foreach}
{foreach from=$allIDs item=someID name=findmyID}
{if $currentID == $someID}{$currentkey = $smarty.foreach.findmyID.index}{/if}
{/foreach}
<p class="next-button">
{$nextkey = $currentkey+1}
{if isset($allURLs[$nextkey])}
<a href="{$allURLs[$nextkey]}">Next article</a> >
{/if}
</p>
<p class="prev-button">
{$prevkey = $currentkey-1}
{if isset($allURLs[$prevkey])}
< <a href="{$allURLs[$prevkey]}">Previous article</a>
{/if}
</p>
In the detail template of the module you should add these lines at the spot you want to have the buttons in the template:
{News summarytemplate='prev_next_links'}
Working example
Comment Form
ReviewManager
ReviewManager
3 Comments
Thanks for the article.
Another similar example where you can get the entire article object to style the prev/next links as you wish:
First you must do a {$news_article=$entry scope=global} in your News detail template
Then create a news summary template with :
{if isset($news_article)}
{$currentID=$news_article->id}
{$prevTmp=null}
{foreach $items as $article}
{if ($article->id == $currentID) and $prevTmp}
{* Previous found *}
{$prevArticle=$prevTmp}
{elseif ($prevTmp->id == $currentID)}
{* Next found *}
{$nextArticle=$article}
{break}
{/if}
{$prevTmp=$article}
{/foreach}
{/if}
{* DISPLAY : *}
{if isset($prevArticle)}
< Previous: {$prevArticle->title}
{/if}
{if isset($nextArticle)}
Next: {$nextArticle->title}
{/if}
And then you must call the news summary action in the current news detail template.
I never tried, but you did already something like:
{$currentID = $entry->id scope=global}
{News category='foo' summarytemplate='prev_next_links'}
Hi,
Is it possible to alter this code to browse back and forth only within a specific category?
Thanks, Ollie