Random Nodes with Views?
nofue - August 11, 2006 - 02:05
Servus, folks.
I want a floating block showing a random quote. I can't figure how to get a random selection from these CCK records called 'quotes' using the view.module... I found some notes that the former "random node" option was dropped in spring because of some new feature, but I couldn't find any further hint. The online help and some docs still say chosing "random node" should do the trick, but that's gone now.
So how do I select a random record from CCK using view?
TIA,
Norbert

Random
Really? I have it on one of my sites, which has the latest version of the module for 4.7. Here's how I did it (instructions may be verbose, but this may be useful for those new to Views and searching for how to display a random post in a block):
Thanks for the tip
That was on my list of things to figure out this week. Scratch it off now! Thanks a bunch.
Trevor Twining
http://www.trevortwining.info
Thanks a million
Works like a charm -- you made my week.
Norbert
-- form follows function
Me Too!
I just wanted to add my thanks for this little how-to. THANKS!
Rich Yumul
www.sagetree.net
Simplified
I simplified this how-to a little, adding the PHP that views exports to save a little time, in a handbook page for linking to a random blog post in a block.
This works extremely well -
This works extremely well - with one tiny little problem (there's always one who complains isn't there).
The block section of a view allows for checking a checkbox which will then go to the page view of the same view. This is useful - it keeps the same filters etc etc - but - of course it also keeps the random sort.
Is there any approach which will allow for the block sort order to be random but to get a link to a page view where the sort is something else?
I'm wondering about contemplate module and manually adding the link in the template (having two views, one for the block, one for the page) - but is this the right way?
I did this as well because
I did this as well because of a few issues with contemplate recently. But, I didn't see the "random" option which is great! I want it to look more like a teaser and give the view a length so it will cut off after so many lines. I tries changeing the block height but it didn't work. Any ideas?
~~~~~~~~~~~~~~~~
Kris
Current project: www.cribfax.com
one of the best tutorials I've seen
Thanks Richard. Generally people aren't willing to make a step by step tutorial for something that seems so simple. It helps so much. Thank you.
Excellent step by step
Excellent step by step guidelines
Views2
In views2, simply add the Sort criteria of Global:Random
dude, you da man (or woman, not sure)
thanks for the Views2 addition. big help.
coolio
just used this method on a page view, cheers dude
Automatically refreshes after x seconds?
Excellent tutorial works really well.
Just wanted to know:
Is it possible to make the block refresh via javascript or some other means? E.g. every 5 seconds another random quote appears, etc... ? Is this possible wiht viewS?
=-=
investigate the views cycle module or one of the other views addons that may do what you ask.
top work!
thanks richard, works a treat :)
I've just tried this method.
I've just tried this method. It works fine when im logged in as admin, but when im logged out and viewing the page as any normal person would the random function doesnt work.
Any ideas?
exclude current node from view
and don't forget that it is always a good idea to exclude current node, so the page you are viewing the random block on doesn't show up in your block!
Drupal 5 http://drupal.org/node/131547
Drupal 6 requires no code! another reason to switch :)
To exclude the current node from the view:
1) Add another argument = Node:Nid
2) Select "Action to take if argument is not present" = "Provide default argument"
3) Select "Default argument type" = "Node ID from URL"
4) Select "Exclude the argument"
source:drupaleasy.com
This is very
This is very helpful,
Thanks,
Izzy
Bookmarking, anyone knows how
Bookmarking, anyone knows how to deal with this using the taxonomy term as argument, so showing random nodes in a block related to the term in the url (taxonomy/term/%) ?
Thanks a lot for your reply!
Greetings,
Martijn
Different Color Node and Block Question
I have a tricky question
Is there any way to make the randomizing content-type a block instead of a node?
Because my blocks are grey and my nodes are white with rounded edges
When I follow these instructions my grey block shows the randomizing article nodes with the node with the white background inside it
http://img197.imageshack.us/img197/9240/croppedoffadproblem.jpg
It also pushes the ad off the right edge of the page because of the left margin space
And it puts the node comment count below it which is no good
In blocks I can copy and paste the ad html and it fits perfectly centered and doesn't put a different background color, but I don't know how to randomize it
Is there any way to randomize ads in a block with views?
Or is there a way to set the content-type to be a block instead of a node?
That's a styling question,
That's a styling question, not a Views question. Install firebug, then inspect your block. It will quickly become obvious how to style the block to achieve what you want.
That said, there are several ad managing modules here, which depending on context may already do what you want. You might check to make sure you're not re-inventing the wheel.