how to show child documents order by date(a custum field in child page type) in cms?

Muhammad Kaleem asked on May 7, 2019 13:55

i have two page types one is parent other is child, there are no of documents under the parent document, i want to show child documents order by date(a custom field in child page type), if anyone know please suggest

thanks

Recent Answers


Roman Hutnyk answered on May 7, 2019 17:59

If you're using DocumentQuery to get child pages, e.g.

var pages = DocumentHelper.GetDocuments()
    .Types("DancingGoat.Article")
    .Path("/Articles/", PathTypeEnum.Children)
    .WhereStartsWith("DocumentName", "Coffee")
    .OnSite("DancingGoat")
    .Culture("en-us")
    .WithCoupledColumns();

DocumentQuery has OrderBy method which allows you to specify a column to sort by.

Also Kentico generates Info and Provider classes for the page types you create, so you could easily get content with Provider class, e.g.

Home homeNode = HomeProvider.GetHome("/Home", "en-us", SiteContext.CurrentSiteName)
                                        .Columns("DocumentName", "DocumentID", "HomeHeader", "HomeTextHeading", "HomeText");

Provider class should also provide you with a method to order the result. See more details here.

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 7, 2019 18:12

thanks Roman Hutnyk, i have asked this for cms documents, in a way that all child documents under a tree node should be ordered according to date provided in custom field...

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on May 7, 2019 18:18

If you're talking about cms tree (admin section) - they can be ordered only manually.

You could hook into document events and implement some code to order documents the way you need, but I'm not sure it is worth of an efforts.

1 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 8, 2019 08:57

thanks, Roman Hutnyk

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.