Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

  • Exits

  • Categories

  • Archives

  • Tags list

    • Blog sponsors

    • Exits

    • Visitors’ track

      Locations of visitors to this page

    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:

    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.

    • Delicious
    • Google Bookmarks
    • Yahoo Bookmarks
    • Windows Live Favorites
    • Technorati Favorites
    • Digg
    • Slashdot
    • StumbleUpon
    • Read It Later
    • Twitter
    • Share/Bookmark

    5 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. Bogdan Says:

      Chris, your Testimonials block is amazingly familiar :)

      Other than that – nice site.

    3. 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

    4. 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.

    5. jeremy mayhew Says:

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

    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>