Copied to clipboard

Flag this post as spam?

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


  • Kerri Mallinson 113 posts 497 karma points
    Aug 28, 2014 @ 11:35
    Kerri Mallinson
    0

    Navigating to last sibling node

    Hi,

    I'm using 7.1.4, i'm trying to get the last sibling of the current page in my navigation so that if there is no previous page it goes to the last page,

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    <div class="case-controls">

    @if (@CurrentPage.Previous() != null) {

            <a href="@CurrentPage.Previous().Url"><img src="/images/shared/left-icon.gif" alt="" /></a>

    }

    else{

    <a href=""><img src="/images/shared/left-icon.gif" alt="" /></a>

    }

    <a href="@CurrentPage.Parent.Url"><img src="/images/shared/grid-icon.gif" alt="" /></a>

    @if(@CurrentPage.Next() != null){

    <a href="@CurrentPage.Next().Url"><img src="/images/shared/right-icon.gif" alt="" /></a>

    }

    else{

    <a href="@CurrentPage.Up().Down().Url"><img src="/images/shared/right-icon.gif" alt="" /></a>

    }

    </div>

     

    Any help would be greatly appreciated.

    Thanks!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 28, 2014 @ 13:13
    Dennis Aaen
    0

    Hi Kerri.

    If I have understood your question correctly, then when there is no previous pages, then you want a link to the last page on the same level.

    If so I think that I have found a way that you could do it.

    <div class="case-controls">
        @if (@CurrentPage.Previous() != null) {
            <a href="@CurrentPage.Previous().Url"><img src="/images/shared/left-icon.gif" alt="" /></a>
        }

        else{
            <a href="@CurrentPage.AncestorOrSelf(1).Children.Last().Url"><img src="/images/shared/left-icon.gif" alt="" /></a>
        }
       
        <a href="@CurrentPage.Parent.Url"><img src="/images/shared/grid-icon.gif" alt="" /></a>

        @if(@CurrentPage.Next() != null){
            <a href="@CurrentPage.Next().Url"><img src="/images/shared/right-icon.gif" alt="" /></a>
        }
        else{
            <a href="@CurrentPage.Up().Down().Url"><img src="/images/shared/right-icon.gif" alt="" /></a>
        }

    </div>

    Hope this helps, if you have any further questions don't hesitate to ask again.

    /Dennis

  • Kerri Mallinson 113 posts 497 karma points
    Aug 28, 2014 @ 15:30
    Kerri Mallinson
    0

    Hi Dennis,

    Thanks for the reply, sorry if i wasn't clear enough.  What i am trying to find is the last node on the same level i am currently on, `@CurrentPage.AncestorOrSelf(1).Children.Last().Url takes me up a level.

    my structure is:

    Home

         About

         Work

         Blog

             Blog Article 1

             Blog Article 2

             Blog Article 3

             Blog Article 4

        Contact

    The navigation is on the Blog Articles, its a left and right arrow enabling users to scroll to the next/previous article, when im on Article 1 i want the left arrow to go to the last Article, the code you have given takes me from Blog Article 1 to Contact.

    Thanks again!

    Kerri

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 28, 2014 @ 15:39
    Dennis Aaen
    100

    Hi Kerri,

    What about this:

    <div class="case-controls">
        @if (@CurrentPage.Previous() != null) {
            <a href="@CurrentPage.Previous().Url"><img src="/images/shared/left-icon.gif" alt="" /></a>
        }

        else{
            <a href="@CurrentPage.Parent.Children.Last().Url"><img src="/images/shared/left-icon.gif" alt="" /></a>
        }
       
        <a href="@CurrentPage.Parent.Url"><img src="/images/shared/grid-icon.gif" alt="" /></a>

        @if(@CurrentPage.Next() != null){
            <a href="@CurrentPage.Next().Url"><img src="/images/shared/right-icon.gif" alt="" /></a>
        }
        else{
            <a href="@CurrentPage.Up().Down().Url"><img src="/images/shared/right-icon.gif" alt="" /></a>
        }

    </div>

    Did the code do what you are after, I hope so.

    /Dennis

  • Kerri Mallinson 113 posts 497 karma points
    Aug 28, 2014 @ 15:51
    Kerri Mallinson
    0

    Thanks Dennis - this works!

Please Sign in or register to post replies

Write your reply to:

Draft