Prev/Next links in CGBlog

Adding Prev/Next links to the CGBlog detail pages without using UDT's.

I was looking for an easy way to add prev/next links to the CGBlog detail pages and found some threads in the forum containing an impressive UDT for this purpose.

I would like to demonstrate the power and simplicity of "Smarty template code" by making my own version of this UDT...
(ps: i also believe this should be future-proof as opposed to the UDT)

In CGBlog, create a separate (extra) summary template and name it something like "prev-next-links":

{foreach from=$items item=prevnextentry}{capture append='allIDs'}{$prevnextentry->id}{/capture}
{capture append='allURLs'}{$prevnextentry->detail_url}{/capture}
{/foreach}

Then add the following code to your detail template:

{capture assign='currentID'}{$entry->id}{/capture}
{capture assign="junkk"}{CGBlog summarytemplate="prev-next-links" action="default"}{/capture}
{foreach from=$allIDs item=someID name=findmyID}
     {if $currentID == $someID}
          {assign var=currentkey value=$smarty.foreach.findmyID.index}
     {/if}
{/foreach}
{assign var=nextkey value=$currentkey-1}
{if isset($allURLs[$nextkey])}{$allURLs[$nextkey]}{/if}
{assign var=prevkey value=$currentkey+1}
{if isset($allURLs[$prevkey])}{$allURLs[$prevkey]}{/if}

And as a bonus, you can easily select categories, change the sorting, ... by changing {CGBlog summarytemplate="prev-next-links" action="default"} to your liking :)

You can also grab extra information in the summary template like paths to images (created with "custom Field Definitions") to create on hover image preview effects etc...

Let me know what you think!

Greetings,
Manuel

Comments