+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / How do I get the 10 newest and 10 oldest pages?

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

3 posts, 0 answered
  1. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    25 Sep 2012
    Link to this post
    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")


  2. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    25 Sep 2012
    Link to this post
    (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.
  3. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    25 Sep 2012
    Link to this post
    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.
3 posts, 0 answered