I'm having a senior moment and wondering if someone can give me a hand.
I've got the following layout.
News
Year
Month
I have my news showing in each year and month which is fine, however what I want todo is in "news" have the latest 4 news showing in the "news" template
How can I add a for each loop in "news" that will go through the years and month and fetch latest posts with doctype "newsItem"
To add to Huw's reply, if you use Models Builder you could add .OfType<NewsArticle>() before the ordering to explicitly order by the strongly typed property (e.g. OrderByDecending(o => o.PublishedDate)).
Edit: You may also use DescendantsOrSelf<NewsArticle>() rather than also adding OfType<T>().
Umbraco 13 for each loop for root
Hello,
I'm having a senior moment and wondering if someone can give me a hand.
I've got the following layout.
I have my news showing in each year and month which is fine, however what I want todo is in "news" have the latest 4 news showing in the "news" template
How can I add a for each loop in "news" that will go through the years and month and fetch latest posts with doctype "newsItem"
Thanks
Hi Matt,
On your news page you can use something like
To add to Huw's reply, if you use Models Builder you could add
.OfType<NewsArticle>()
before the ordering to explicitly order by the strongly typed property (e.g.OrderByDecending(o => o.PublishedDate)
).Edit: You may also use
DescendantsOrSelf<NewsArticle>()
rather than also addingOfType<T>()
.Thanks that worked great.
How could I use this to show on my home page too?
Cheers
is working on a reply...