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).
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);
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
Can't believe I missed it.
But how can I check their type & visibility?
Hi Eli,
Mu much better to use these lines:
How to check visibility and document type alias:
Thanks,
Alex
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
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);
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
Hi All,
Here is what I have done. Seems to do the trick.
Obvs switch out my CaseStudyDetailsPage for IPublishedContent or whatever page type you are using.
IEnumerable
is working on a reply...