Please help me . I have this structure in the blog application i am building (blogs in certain month and year)
So, am retrieving the blogs under each month and year . So when am displaying a particular blog, i have a pagination to display the next blog
So i have this pagination structure on each blog page (eg tomb raider) ..
Because the model is displaying a specific blog or all the blogs in a certain month , it doesn't show next and Previous blogs for the blogs that are in another folder of seperate Month or year
BUt i need a way to always next or do previous on the blog page in the next month or year . Please help me . i know there is always a way around this .
That displays several blogs on this current . I now have about 7 Pages of this picture :
I want to display this current Page with one blog with the buttons below .such that when i click the older or previous button even when the blog Month has just one blog, it still shows or goto the Older blog in the Older month or Newer blog in the following month thats current blog is in when it doesnt have more than one blog in its current Month .
Oh, I had assumed you were using colResults to get the previous/next posts. It seems that is not the case.
First, you'd get all of the posts:
var allPosts = objBlogRoot
// Get all posts.
.DescendantsOrSelf("SmartBlogPost")
// Get an anonymous object with a few key values (for improved speed).
.Select(x => new
{
Node = x,
Id = x.Id,
Date = x.GetPropertyValue("smartBlogDate")
});
Next, you'd get the post date node:
var postDate = objPost.GetPropertyValue("smartBlogDate");
Next, you'd get the previous node:
var previous = allPosts
// Exclude the current node.
.Where(x => x.Id != objPost.Id)
// Older posts.
.Where(x => x.Date <= postDate)
// Order by date (descending).
.OrderByDescending(x => x.Date)
// First of the filtered posts.
.FirstOrDefault();
Next, you'd get the next node:
var next = allPosts
// Exclude the current node.
.Where(x => x.Id != objPost.Id)
// Exclude the previous node (in case many have the same date).
.Where(x => previous == null || x.Id != previous.Id)
// Newer posts.
.Where(x => x.Date >= postDate)
// Order by date (ascending).
.OrderBy(x => x.Date)
// First of the filtered posts.
.FirstOrDefault();
I'm sure you can figure the rest out. Note that I didn't test the above code, but the general idea should work (you may have to tinker with some things). Also, I would highly recommend you add some caching, as this code could be fairly slow.
I have the Next and previous button Hidden on the BLOGS that have just one blog in that MONTH . Below is what the picture looks like . The other two buttons are hidden because previous() and next() are null
Umbraco Pagination with Next And Previous
Hi ,
Please help me . I have this structure in the blog application i am building (blogs in certain month and year)
So, am retrieving the blogs under each month and year . So when am displaying a particular blog, i have a pagination to display the next blog
So i have this pagination structure on each blog page (eg tomb raider) ..
Because the model is displaying a specific blog or all the blogs in a certain month , it doesn't show next and Previous blogs for the blogs that are in another folder of seperate Month or year
BUt i need a way to always next or do previous on the blog page in the next month or year . Please help me . i know there is always a way around this .
My code snippet below ..
colResults= Model.Content.DescendantsOrSelf("SmartBlogPost").OrderByDescending(x => x.GetPropertyValue
Instead of this:
Try this:
That way, you are getting all of the blog posts rather than ones that are a descendant of the current page.
Hi Nicholas,
That displays several blogs on this current . I now have about 7 Pages of this picture :
I want to display this current Page with one blog with the buttons below .such that when i click the older or previous button even when the blog Month has just one blog, it still shows or goto the Older blog in the Older month or Newer blog in the following month thats current blog is in when it doesnt have more than one blog in its current Month .
Oh, I had assumed you were using
colResults
to get the previous/next posts. It seems that is not the case.First, you'd get all of the posts:
Next, you'd get the post date node:
Next, you'd get the previous node:
Next, you'd get the next node:
I'm sure you can figure the rest out. Note that I didn't test the above code, but the general idea should work (you may have to tinker with some things). Also, I would highly recommend you add some caching, as this code could be fairly slow.
Hi Nicholas,
Thank you for taking your time to look into it . However , It still doesnt work . The next and Previous New code below :
I have the Next and previous button Hidden on the BLOGS that have just one blog in that MONTH . Below is what the picture looks like . The other two buttons are hidden because previous() and next() are null
You should not be calling either of these:
With that code, you are essentially attempting to find the previous of the previous and the next of the next.
Thank you Nicholas . It worked like baked beans haha. Thanks
Please do you know anything on this . I have tried several blogs
https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/76421-umbraco-multisite-language-translation
Hello All!
I'm trying to add a latest blog post section to the about page of my site however the following line is returning null
IPublishedContent objBlogRoot = Model.Content.AncestorOrSelf("SmartBlogBlog");
it works fine on the root page but not on the child page.
could some one please advise?
kind regards, H
What happens if you manually loop through each parent? That is:
(Obviously, you'd want to do that in a while loop or something of that sort.) Do you see a content node with a document type of "SmartBlogBlog"?
is working on a reply...