Adding previous and next links to the modules detail pages

  Previous article Next article  

Adding previous and next links to the modules detail pages

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1
  Last updated: 14-07-2016
  Comments: 2

This 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.

The method described here originates from the IDT blog and was written by Manuel in 2012. The tutorial there doesn't work anymore with the latest CMSMS™ releases due to the Smarty scope settings. Beside that the original tutorial was written for the CGBlog module and the next-prev buttons are now included in the module package as you can see here at CMS can be Simple.org.

This updated tutorial will show you the same method that works in the new CMS Made Simple 2.x series, but for modules like the News, Company Directory and others! You might need to change some Smarty variables like $the_entry->moreurl to get the correct URL for that module.

  How to use

Create a new News summary template, named "prev_next_links", with the content:

{foreach from=$items item=the_entry}
  {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>&nbsp;&gt;
  {/if}
</p>

<p class="prev-button">
  {$prevkey = $currentkey-1}
  {if isset($allURLs[$prevkey])}
    &lt;&nbsp;<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:

{$currentID = $entry->id scope=global}
{News summarytemplate='prev_next_links'}

A2 Webhosting CMS Made Simple

  Working example



A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  2 Comments

CMS Made Simple 2.2.2 - Tutorials, tips and tricks - CMSMS 2.2.2

Adding previous and next links to the modules detail pages

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1
  Last updated: 14-07-2016
  Comments: 2

A2 Webhosting CMS Made Simple