Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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.
Can't believe I missed it.
But how can I check their type & visibility?
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, 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?
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);
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:
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted