By nofue on
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
Comments
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):
(Username formerly my full name, Richard Eriksson.)
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
Freelance Drupal Dev
Theme/Modules/Sitebuilding
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.com
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.
(Username formerly my full name, Richard Eriksson.)
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?
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.
Thanks
Thanks binford2k . That short tip was a saving of 2 hr stress
Thanks
I was about to pull my hair out when i saw your post. I was using views 2 and i did not see random at first. Thanks alot. I wish we had quick tips like this for themes. Themes always gives me a head ache. Especially css stuff. ahhhh.
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.
Not so good
I dont like this variant. Look at the query
IT SELECTS ALL NODES!!! But i have 7000 of nodes and for one random do this query? nooo... You need something like this
Select random content, then sort
Is there a way in views to select a random set of content that meets the filter criteria, and then apply a different sort? For example, I would like to select a random set of something and then sort the selected set by name.
Thanks for the tutorial. It
Thanks for the tutorial. It saves me a lot of time...
:)
Thank You This solved my
Thank You
This solved my problem and works a treat! :)
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?
I have same problem. did you
I have same problem. did you find out what it was?
I tried refreshing the page
I'm using drupal 6
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.
For Drupal 7.12?
Can it be used for Drupal 7.12?
I am dying to create a randomly quote every time it's loaded, but I never know how to. Anyone here can help me, please? Explain step by step? :)
I am so thankful to anyone who want to help us!
=-=
create a content type to store quotes in the DB
create a view, create a display in the view, filter the quote content type in the view, set the sort to random, save the view.
visit your new display
if you want it in a block be sure to create a block display
Random sort criteria works
Random sort criteria works great! Thanks for that simply solution!
But i cant figure out some additional thing. How to exclude from this block with random nodes current displayed node. I mean i dont wanna display randomly nodes in block when user is visiting that specific node. I hope thats clear. Somefing like filter for NID: 'is not equal to current NID from URL '
Thank for your help!
relationship?
I believe this IS possible in Views. Unfortunately I am only going to supply some hints because I haven't done it. (But at least it is better than just saying "subscribe" because I am interested in the reply.)
My understanding is you can add a "relationship" (in the third column of the Views UI). You can set this to Node ID and I think there is some is/is not type logic here.
In Views 2 a Block View could not get information from the url, but I think in Views 3, this is what the relationship allows. Please let me know if that helps at all.
A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com
reletionship, but which and
reletionship, but which and how? i have no idea.
I tried contextual filter: Content: Nid, but i am able only to do something opposite to what i need ;-) I can use option "Provide default value: Content ID from URL. This way i can display exactly the same node i am currently visiting. But maybe using this contextual filter it is possible to do it somehow with PHP Code filter? Anyone can provide php code for that task?
so close
You are so close, I think. Isn't there a check box in the contextual filter: Content: Nid that allows you to invert the results?
A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com
I found it :)
Your clue was very helpful and you are totally right. There is an option 'Exclude':
In the last section 'more' of the Contextual filter: Nid, under the administrative title.
Also useful hint i found here: http://drupal.stackexchange.com/questions/17284/inverse-of-drupal-contex...
So, i think question in this thread is solved :)
Clear cache
Muchas gracias por compartir, me ha servido justo para lo que necesitaba.
Importante indicar en el parámetro de cache en las opciones avanzadas "NONE" de la vista.
Saludos