How do I get the 10 newest and 10 oldest pages?

Posted by Community Admin on 03-Aug-2018 00:01

How do I get the 10 newest and 10 oldest pages?

All Replies

Posted by Community Admin on 25-Sep-2012 00:00

I am trying to create an admin widget that shows me the 10 oldest pages (longest time since last edit) and the 10 newest pages. (most recent edits)

Here is the code I have below. For some reason both are returning the SAME result set. Any idea why?

// Get the 10 newest pages
IQueryable<PageNode> NewPages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).Where(p => p.ApprovalWorkflowState == "Published").OrderByDescending(p => p.LastModified.Date).Take(10).Get();
 
// ...and the 10 oldest pages
IQueryable<PageNode> OldPages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).Where(p => p.ApprovalWorkflowState == "Published").OrderBy(p => p.LastModified.Date).Take(10).Get();

I have also tried to use the following with no difference.
.ThatArePublished()
 
// instead of:
 
.Where(p => p.ApprovalWorkflowState == "Published")


Posted by Community Admin on 25-Sep-2012 00:00

(I'm showing my rust with this... ;-)

Been a while since I've written a query against the fluent API. I don't have an answer yet, but the documentation is much improved since the last time I checked:
http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/pages/querying-pages 

I'll post an update if I solve it.

Posted by Community Admin on 25-Sep-2012 00:00

This will get the last 10 pages edited:

PageManager pageManager = PageManager.GetManager();
IQueryable<PageNode> pages = pageManager.GetPageNodes().OrderByDescending(n => n.LastModified).Take(10);

This modification of the query, will filter out the draft pages, leaving latest published pages:
IQueryable<PageNode> pages = pageManager.GetPageNodes().Where(n => n.ApprovalWorkflowState == "Published").OrderByDescending(n => n.LastModified).Take(NumberToDisplay);

The "PageManager" doesn't appear to have the ability to filter out Backend pages whereas the fluent method, App.WorkWith().Pages, does.

This thread is closed