+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

Quick Tip: “Randomly” Sorting Content in Native Widgets

by Tim Williamson

Here’s a quick way to achieve a “random” sort using native Sitefinity widgets. This requires no custom code but is probably a completely “off label” use of the property involved. Moving on…

Locate the SortExpression field for the widget you want to modify. Using DynamicContent as an example, click “Edit” then click through to Advanced -> ControlDefinition -> Views -> DynamicContentMasterView. SortExpression can be found near the bottom of the list. 

Once you’ve located the field, paste the following expression there.

DateCreated.ToString().Substring((DateTime.Now.Second % 10), 4)

This returns a slightly different string (each second) that Sitefinity can use to sort the content by. I only tested this on the DynamicContent and BlogPosts widgets but don't see any reason it wouldn't work on anything with a SortExpression.

Please, let me know if it works for you. Enjoy!

3 comments

Leave a comment
  1. Robert Mar 27, 2014

    Thanks for the great tip. Unfortunately this is not working for me. Sitefinity 5.2.

    I don't get an error, just the same sorting every time I refresh. I'm using it with BlogPosts widget.

    Is this supposed to work in 5.2?

     Any help would be greatly appreciated.

  2. Mabel May 20, 2014

    I have using Sitefinity 6.1 and I tried to use this tip for randomly sort the list widget of a dynamic module, but I always get the same sorting.

    Is there any other way to achieve this  without create a custom widget?

    Thanks!

  3. Vesselin Jun 17, 2016
    Probably the page is cached and that's why you are getting the same results every time

    Leave a comment