Copied to clipboard

Flag this post as spam?

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


  • Eli 15 posts 95 karma points
    Mar 30, 2019 @ 03:14
    Eli
    0

    Get previous and next sibling from same type

    Hi,

    I am trying to implement "Next" and "Previous" buttons in a blog article page. For doing so I simply need to get the next/previous siblings of the current page (from the same type).

    Couldn't find a proper answer for this issue.

    Cheers

  • Eli 15 posts 95 karma points
    Mar 31, 2019 @ 01:04
    Eli
    0

    Can't believe I missed it.

    CurrentPage.Next()
    CurrentPage.Previous()
    

    But how can I check their type & visibility?

  • Alex Skrypnyk 5273 posts 19288 karma points MVP 3x admin c-trib
    Apr 01, 2019 @ 12:48
    Alex Skrypnyk
    1

    Hi Eli,

    Mu much better to use these lines:

    var prev = Umbraco.AssignedContentItem.Previous();
    var next = Umbraco.AssignedContentItem.Next();
    

    How to check visibility and document type alias:

    var isVisible = prev.IsVisible();
    var documentTypeAlias = prev.DocumentTypeAlias;
    

    Thanks,

    Alex

  • Eli 15 posts 95 karma points
    Apr 02, 2019 @ 23:53
    Eli
    0

    Thanks Alex, but I want to retrieve the next sibling that is visible from the same type, and not just get the next/previous one and check if they are visible and their type. Is there an short query for that or should I iterate over all of my siblings until I get one that fits me?

    Cheers

  • Bharti 8 posts 74 karma points
    Apr 01, 2019 @ 09:33
    Bharti
    0

    Hi Eli,

    Try using:-

    Getting The Current Page Via The Database To get the content via the database, so you can write to it as well, you need to use a different API, like so:

    var currentPageId = UmbracoContext.Current.PageId;
    IContent content = ApplicationContext.Current.Services.ContentService.GetById(currentPageId);

  • Alex Skrypnyk 5273 posts 19288 karma points MVP 3x admin c-trib
    Apr 01, 2019 @ 12:50
    Alex Skrypnyk
    2

    Hi Bharti

    Never user "ContentService" for displaying content.

    "ContentService" is for making changes in the database. It's a heavy method, on the pages user IPublishedContent always!

    Have a look at "Common Pitfalls & Anti-Patterns" and never do it like that:

    https://our.umbraco.com/documentation/Reference/Common-Pitfalls/

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft