Drupal Views: how to display random nodes/content
4th May 2009
Today I had a task of displaying random node in a Views-generated sidebar block.
This is how to do that in Drupal 7 (Views 3):
- edit the view which makes the block available (follow http://your.site/admin/build/views/viewname/edit)
- in the Sort Criteria section (under Filter), look for and add Global:Random.
This is how to do that in Drupal 6 (Views 2):
- edit the view which makes the block available (follow http://your.site/admin/build/views/viewname/edit)
- in the Sort Criteria section, add the Random criteria.
It can’t be simpler than that.
February 20th, 2010 at 15:29
Wow, you have no idea how long i have been trying to work that out
April 9th, 2010 at 19:45
The random sort is a great tip! I’ve got a site in dev and attempted to use the random block module but had numerous issues with it. This is much easier.
Do you know if there is an easy way to replace the block title with the title of the node from the view? I’m using random with the return limited to one node.
Jon
April 9th, 2010 at 22:22
You can use block template to override block’s title. Views UI provides nice and detailed list of template files to use for styling output – look for ‘Theming information’ or alike, your template filename might look like block-views–viewname.tpl.php
Theming with template files is relatively easy (and fast, and powerful), but may require a significant amount of time to get started. If you have a recent Drupal book with a chapter on theming – give it a try.
August 10th, 2010 at 5:13
thank you so much! such a simple solution but without your assistance, it was hidden and frustrating. thank you!
September 23rd, 2010 at 21:39
Easy solution.
Thanks
December 12th, 2010 at 15:30
This tip is simple and really useful. I was trying to make this work through dedicated modules but the views option is very straightforward.
May 2nd, 2011 at 9:10
Wait! Where’d it go in Views 7.x-3.x-dev !? Rats!
July 7th, 2011 at 18:32
Has this been re-added since 7.x? The randomizing feature is something that really needs to get back in!
September 26th, 2011 at 2:58
for anyone using Views 3 (7.x-3.0-rc1) and looking for random sort criteria, it is available under “Global:Random” in Sort Criteria.
September 26th, 2011 at 13:52
Thanks, I’ve updated the post.
December 12th, 2011 at 3:18
That’s great, thanks!
February 3rd, 2012 at 1:52
Where on earth IS Global:Random?! I’m using the latest D7 with v3, and can’t find it anywhere. I’m only offered options to sort ASC/DEC with no randomness to be found anywhere
I was going to upload a screenshot, but can’t see how to do it.
Thanks in advance. This is driving me mad!
February 3rd, 2012 at 1:58
Ok, I’ve found it. Under Filter. Why didn’t anyone SAY filter? Why isn’t it mentioned in the doco?
There are a million options for Views, and if it’s not documented, then it’s incredibly hard for newbies like me to learn.
I’m not asking for a fancy schmancy book, just an extra word or two here and there.
Thanks!