Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    • Archives

    • Recent comments

    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):

    1. edit the view which makes the block available (follow http://your.site/admin/build/views/viewname/edit)
    2. in the Sort Criteria section (under Filter), look for and add Global:Random.

    This is how to do that in Drupal 6 (Views 2):

    1. edit the view which makes the block available (follow http://your.site/admin/build/views/viewname/edit)
    2. in the Sort Criteria section, add the Random criteria.

    It can’t be simpler than that.

    Share

    13 Responses to “Drupal Views: how to display random nodes/content”

    1. Chris Says:

      Wow, you have no idea how long i have been trying to work that out :P

    2. JonR Says:

      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

    3. Bogdan Says:

      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.

    4. jeremy mayhew Says:

      thank you so much! such a simple solution but without your assistance, it was hidden and frustrating. thank you!

    5. xjkwak Says:

      Easy solution.

      Thanks

    6. Mrigank Says:

      This tip is simple and really useful. I was trying to make this work through dedicated modules but the views option is very straightforward.

    7. Craig Says:

      Wait! Where’d it go in Views 7.x-3.x-dev !? Rats!

    8. Matt Says:

      Has this been re-added since 7.x? The randomizing feature is something that really needs to get back in!

    9. Wayne Says:

      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.

    10. Bogdan Says:

      Thanks, I’ve updated the post.

    11. littleguy Says:

      That’s great, thanks!

    12. Ed Love Says:

      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!

    13. Ed Love Says:

      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!

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>