Display a random node using Views

Oh I love it when a solution is so simple!

I recently created a new page and block using Views for my client (and day job employer) Fork Union Military Academy ( http://www.forkunion.com ) so we could add a "Senior Spotlight" block to the front page, highlighting the accomplishments of the school's honor graduates. The goal was to create a group of about 10 or 15 nodes, built using a custom content type that includes fields for a photo and an audio file for a student interview.

I originally thought I might just change the student displayed in the block manually every few days, but being the lazy sort, I began to think about doing some Drupal razzle-dazzle and pulling the content at random from the group of students so a different student would appear each visit to the page. I considered using the Dynamic Display module in some way, but that seemed a bit too complicated to figure out. I wondered if there might be some kind of PHP programming I could toss in somewhere to randomize the sort order and simply display the first record. Then I decided to google "drupal views random node" and, lo and behold, this blog page showed up in the results and caught my attention.

I quickly learned that ALL you have to do to display a random node in a view is to select "GLOBAL: Random" as the Sort Criteria. That's it?! It's that easy??

Yep, it's that easy.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options