Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I want a list of items (nodes) to display on a page in a random order. Is there any way to do that?
I tried
node.ChildrenAsList.Where("show").Random()
But that only returns 1 item.
I've also tried something like this:
node.ChildrenAsList.Where("show").OrderBy(x => Guid.NewGuid());
But that results in an error too, because I can't use a lambda expression there.
Any other ideas? I can't be the first that needs to shuffle a list of nodes, can I?
It your node is CurrentPage you can use Model.Content instead:
CurrentPage
Model.Content
var random = Model.Content.Children.Where("show").OrderBy(x => Guid.NewGuid());
easiest way is to use .Random(#) Replace # with the number of results or to display all - if there aren't too many - put in a number which will cover the lot.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Randomize a list of Children (DynamicNodeList)
Hi,
I want a list of items (nodes) to display on a page in a random order. Is there any way to do that?
I tried
But that only returns 1 item.
I've also tried something like this:
But that results in an error too, because I can't use a lambda expression there.
Any other ideas? I can't be the first that needs to shuffle a list of nodes, can I?
It your node is
CurrentPage
you can useModel.Content
instead:easiest way is to use .Random(#) Replace # with the number of results or to display all - if there aren't too many - put in a number which will cover the lot.
is working on a reply...