Copied to clipboard

Flag this post as spam?

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


  • Milly 30 posts 130 karma points
    Jun 08, 2017 @ 14:52
    Milly
    0

    Sorting and Creating Next/Previous Buttons

    Hello,

    I have a bunch of nodes in a list view which are sorted by a custom field "postDate"

    enter image description here

    and I've created a next/previous button to navigate through the posts:

    @{
        var blogPost = Model.Content;
    }
    
    <nav aria-label="...">
        <ul class="pagination">
            <li class="page-item @((blogPost.Previous() == null ? "disabled" : null))">
                <a class="page-link" href="@((blogPost.Previous() != null ? blogPost.Previous().Url : null))" tabindex="-1">Previous</a>
            </li>
            <li class="page-item @((blogPost.Next() == null ? "disabled" : null))">
                <a class="page-link" href="@((blogPost.Next() != null ? blogPost.Next().Url : null))" tabindex="-1">Next</a>
            </li>
        </ul>
    </nav>
    

    The problem I'm having is that the nav buttons are getting the next/previous post based on the Sort Order, which isn't the same as postDate:

    enter image description here

    How do I make it so that it navigates to the next post via postDate and not sortOrder? Thanks :) I'm using Umbraco 7.6.1

  • emma burstow 43 posts 251 karma points MVP 3x hq c-trib
    Jun 13, 2017 @ 09:03
    emma burstow
    0

    Hi Milly,

    Have you tried appending the blogPost Url with a .CreateDate?

    First you'd need to change that top snippet to

    var blogPost = Model.Content.Url;

    Then append here

    blogPost.Next().CreateDate

    Would that work?

    Emma

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Jun 13, 2017 @ 09:15
    Paul Seal
    2

    I wrote this partial for my site.

    You are welcome to use it.

    https://gist.github.com/prjseal/85613cb05bea0d62e2fdc4515b46c1d1#file-next-and-prev-buttons-partial-for-umbraco

    Kind regards

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft