Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • William Corry 34 posts 171 karma points
    May 07, 2015 @ 13:10
    William Corry
    0

    Next and previous pages in date order

    I have a document type as a listview with multiple types of documents type children. I wish to add a next and previous button to each post. The issue I have had is when using:

    @CurrentPage.Next().Url 
    @CurrentPage.Previous().Url 
    

    They looped so the latest post would then point to the oldest post (for next) and some where in the wrong published order ie where added after the date wanted so end up in the wrong order for the end user.

    I then tried:

    var newer = CurrentPage.AncestorOrSelf(1).Descendants().Where("NodeTypeAlias == @0 && date > @1", "DOCTYPENAME", CurrentPage.Date).OrderBy("date desc");
    var older = CurrentPage.AncestorOrSelf(1).Descendants().Where("NodeTypeAlias == @0 && date < @1", "DOCTYPENAME", CurrentPage.Date).OrderBy("date desc");
    
    <nav>
        <ul class="pager">
            @if(older.Count() > 0) {
            <li class="previous @previous"><a href="@older.First().Url"><span aria-hidden="true"><i class="fa fa-chevron-left"></i></span> Older</a></li>
    }
            @if(newer.Count() > 0) {
            <li class="next @next"><a href="@newer.First().Url">Newer <span aria-hidden="true"><i class="fa fa-chevron-right"></i></span></a></li>
        }
        </ul>
    </nav>
    

    Which worked kind of as this limited it to one documentype any suggestions where I can allow all documentypes (or even specify multiple documentypes would be fine) that would work off the date property of the document?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 07, 2015 @ 13:38
    Dennis Aaen
    101

    Hi William, 

    The syntax for specify multiple documentypes in the where is looks something like  this: 

    var newer = CurrentPage.AncestorOrSelf(1).Descendants().Where("NodeTypeAlias == @0 || NodeTypeAlias == @1", "DOCTYPENAME1","DOCTYPENAME2";

    So you could try something like this

    var newer = CurrentPage.AncestorOrSelf(1).Descendants().Where("NodeTypeAlias == @0 || NodeTypeAlias == @1  && date > @2", "DOCTYPENAME1","DOCTYPENAME2", CurrentPage.Date).OrderBy("date desc");

    Hope this helps,

    /Dennis

  • William Corry 34 posts 171 karma points
    May 07, 2015 @ 15:38
    William Corry
    0

    Thanks that works altered slightly:

    var older = CurrentPage.AncestorOrSelf(1).Descendants().Where("NodeTypeAlias == @0 && date < @2 || NodeTypeAlias == @1  && date < @2", "DOC1","DOC2", CurrentPage.Date).OrderBy("date desc");
    
Please Sign in or register to post replies

Write your reply to:

Draft