Page 1 of 1
LISE - add previous/next links
Posted: Thu Jan 31, 2019 1:23 pm
by johnboyuk1
Hi all
Can anyone tell me how to achieve this? I want to be able to add previous / next links - like you would find on a blog - to be able to cycle through LISE entries.
I've found this article:
https://cmscanbesimple.org/blog/adding- ... tail-pages
But struggling to work out how to apply not to LISE! Has anyone done this before and wouldn't mind sharing code?
Thanks!
Re: LISE - add previous/next links
Posted: Thu Jan 31, 2019 9:00 pm
by velden
I think it would involve:
- assign current item_id to a variable
- call LISE again (summary action) and inside the summary template loop through all items, assigning previous item_id and moreurl to variables, comparing current item_id with previously saved item_id.
- if current item_id == saved item_id then you should somehow save (or print) the moreurl of the previous item.
- then loop once more to get the next item's moreurl
- special care should be taken if item is the first or last
- note that the $item variable from the summary action may overwrite the $item variable of your detail action/template.
Also think about sorting/ordering if you use any.
Re: LISE - add previous/next links
Posted: Fri Feb 01, 2019 9:40 am
by johnboyuk1
Thanks Velden! This sounds a bit more complicated than my meagre smarty skills though!
If anyone happens to have already done this and can share code I'd be really grateful! I guess my other option could be to modify CGBlog to my needs, I assume that has prev/next links...
Thanks
Re: LISE - add previous/next links
Posted: Fri Feb 01, 2019 9:30 pm
by Dr.CSS
Have you looked at how the News does it..?
Re: LISE - add previous/next links
Posted: Sat Feb 02, 2019 10:41 am
by johnboyuk1
I dont think News does have a next/previous article link?
Re: LISE - add previous/next links
Posted: Sat Feb 02, 2019 11:25 am
by velden
Sometimes you just need to start and try. As I probably need it soon in one of my projects I've made an example.
As you can see it's not difficult. Try to understand the code and learn that CMSMS and Smarty offer so much flexibility. It's just limited by your imagination.
Obviously code can/should be changed to suit your needs. This is just a proof of concept.
LISE
summary template 'nextprevlinks':
Code: Select all
{if $items|@count > 0}
{$prev_url=''}
{$i_am_next=false}
{foreach from=$items item=item}
{if $i_am_next}
<a href="{$item->url}">NEXT ITEM</a>
{break}
{/if}
{if $item->item_id == $current_item_id}
{$i_am_next=true}
{if !empty($prev_url)}
<a href="{$prev_url}">PREVIOUS ITEM</a>
{/if}
{else}
{$prev_url=$item->url}
{/if}
{/foreach}
{/if}
LISE
detail template where you want to have the prev/next links:
Code: Select all
{$current_item_id=$item->item_id}
{LISEnextprev template_summary=nextprevlinks}
Note that if you use the orderby/filter/category parameter somewhere you need to use it here too of course.
Re: LISE - add previous/next links
Posted: Mon Feb 04, 2019 10:39 am
by johnboyuk1
Thanks Velden - believe me, I have been trying...but failing! Many thanks for this, I will take a look and see what I can make of it
I only do 'front-end' really, hence my struggle with programming
j
Re: LISE - add previous/next links - SOLVED
Posted: Mon Feb 04, 2019 10:57 am
by johnboyuk1
Hi Velden
This works perfectly - just wanted to say a big thank you! I was messing around with this for hours, you made it look so simple!