Search code examples
coldfusionmura

Mura CMS - Getting next and previous items in a content collection


I've setup a content collection for a portfolio.

When displaying a page in the content collection, I want to display links to the NEXT and PREVIOUS items in the collection.

Also, is it possible to check if there is a next and previous page (so as not to display link if there isn't one.

Many Thanks in advance.


Solution

  • I ended up with this. May not be the best way to do it, but it works:

    portfolio = $.getBean('feed').loadBy(name='Portfolio').getIterator().getPageIDList();
    
    currentPageNumber = listLen(portfolio) - $.content().getOrderNo() + 1;
    pagePrevious = "";
    pageNext = "";
    
    if (currentPageNumber GT 1)
        pagePrevious = listGetAt(portfolio,currentPageNumber - 1);      
    
    if (listLen(portfolio) GT currentPageNumber)
        pageNext = listGetAt(portfolio,currentPageNumber + 1);
    
    pagePreviousURL = $.getBean('content').loadBy(contentHistID = pagePrevious, siteID = event.getValue('siteID')).getURL();
    pageNextURL = $.getBean('content').loadBy(contentHistID = pageNext, siteID = event.getValue('siteID')).getURL();