Above image is a umbraco structure of my site. In newsDetail.cshtml view, i want to display Next and Previous news item below the current news detail. When I try Previous() and Next() method, it works only for current day item. But I want to display Once Upon a Time in a Galaxy Far Away item when click Next item in News1 detail page.
Thanks in advance.
You'll have to change the documentTypeAliases to match yours.
This will find the "Blog" container and get all descendants of "BlogPost". Then you'll need to find the current page in that list and then use Next or Previous.
Hi Martin,
Thanks for reply. But it works for a same day only. If next news item is in next day or month (may be next year) then it does not work. Can you suggest any other idea??
Ok. The Next() command is the culprit.
Maybe something like this:
Find all the descendants of the blog container
var allBlogPosts = CurrentPage.AncestorOrSelf("Blog").Descendants("BlogPost");
Find the one that is CurrentPage
var currentIndexInAllBlogPosts = allBlogPosts.FindIndex(x => x.Id.Equals(CurrentPage.Id));
Then get the next or previous item in the list if CurrentPage is found:
if (currentIndexInAllBlogPosts > -1){
var nextItem = allBlogPosts[currentIndexInAllBlogPosts +1];
var previousItem = allBlogPosts[currentIndexInAllBlogPosts -1];
}
Of course you need to check so that the index isnt out of bounds.
News Item: Find Next and Previous news item.
Above image is a umbraco structure of my site. In newsDetail.cshtml view, i want to display Next and Previous news item below the current news detail. When I try Previous() and Next() method, it works only for current day item. But I want to display Once Upon a Time in a Galaxy Far Away item when click Next item in News1 detail page. Thanks in advance.
Hi Sabin,
Don't know if this will work, but something like this maybe:
You'll have to change the documentTypeAliases to match yours.
This will find the "Blog" container and get all descendants of "BlogPost". Then you'll need to find the current page in that list and then use Next or Previous.
/Martin
Hi Martin, Thanks for reply. But it works for a same day only. If next news item is in next day or month (may be next year) then it does not work. Can you suggest any other idea??
Regard:
Sabin
Hi,
Ok. The Next() command is the culprit. Maybe something like this:
Find all the descendants of the blog container
Find the one that is CurrentPage
Then get the next or previous item in the list if CurrentPage is found:
Of course you need to check so that the index isnt out of bounds.
Hope that helps.
/M
Hi Martin,
Lots of Thanks. It works. Yeah, I code to check the index out of bounds. Here is my code:
Front End:
Hope further help from you. Thanks Again.
Cheers, Sabin
is working on a reply...