[support] How to show random image files in webpage

Amit Vyas vyasamit2007 at gmail.com
Fri Feb 25 11:45:26 UTC 2011


lol... dude just search for "drupal view random node" you will get all. I
didn't write anything...this is just copying and pasting here :-)


   1. create a new *view* in *administer* » *views* » *add* tab.
   2. give it a name. I called mine "*Random*".
   3. click the "Block" section heading to get its settings.
   4. enable "Provide block"
   5. choose a "*View* type". I went with "List *View*" so that I could
   choose which fields display in the block.
   6. type in a title. This will be the title of the block.
   7. type in a number for the amount of nodes you want to display in the
   block. You can use 1 (number one) if you like.
   8. click the "Fields" section heading to get its settings.
   9. add the fields you want. I chose just "*Node*: Title" since I wanted
   just links to the nodes, not the *node* text themselves. You should be
   able to choose whichever field has the quote in your CCK *node*.
   10. click the "Filters" section heading to get its settings.
   11. select "*Node*: Type" and click "Add Filter"
   12. choose the CCK *node* type(s) you want to appear in the block.
   13. select "*Node*: Published" and click "Add Filter". (I keep forgetting
   this one, but it's important, since you probably don't want to display
   unpublished nodes.
   14. click the "Sort criteria" section heading to get its settings.
   15. select "*Random*" and click "Add criteria".
   16. click "Save"
   17. click *administer* » *blocks* and enable the block you titled in step
   #6.

Thanks!

On Fri, Feb 25, 2011 at 5:03 PM, Austin Einter <austin.einter at gmail.com>wrote:

> Thanks Idan
> I have very limited knowledge on views. Know how to create simple views.
>
> Can you give an overview how to make a view with random nodes.
>
> I assume, in nodes we will be printing the images.
>
> Regards,
> Kamal
>
>
>
> On Fri, Feb 25, 2011 at 1:10 PM, Idan Arbel <idan at arbel-designs.com>wrote:
>
>> Hello,
>>
>> why not create a view of random nodes. create a block display for the view
>> and place it in a region at the top of your page?
>>
>> Idan
>>
>>   On Fri, Feb 25, 2011 at 9:23 AM, Austin Einter <austin.einter at gmail.com
>> > wrote:
>>
>>>   Hi All
>>> I would like to show image files (in a random manner) at the top of
>>> webpage.
>>> I want to have a folder that contains all the image files.
>>>
>>> Then I want to have a separate php file (say rotate.php) having logic of
>>> selecting the random image file.
>>> And want to include that rotate.php file from page.tpl.php.
>>>
>>> To start with, I followed the marinelli view.
>>> Used the images and rotate.php (\marinelli\img\banners\rotate.php).
>>>
>>> Copied to image files and rotate.php to path where my page.tpl.php is
>>> present.
>>>
>>> In page.tpl.php, I added the line  include ("rotate.php");
>>>
>>> The rotate.php looks as below. On debugging looks *preg_match *line it
>>> breaks.
>>> Please let me know why line "if ( preg_match( $regex, $file ) ) {"
>>> breaks.
>>>
>>> Regards
>>> Austin
>>>
>>> *<?php*
>>>
>>> */***
>>>
>>> ** randomly select an image from the current directory and return it*
>>>
>>> ***
>>>
>>> ** @todo - consider accepting a local path as $_GET['img'] for overrides
>>> *
>>>
>>> ** to remain compatible with Marinelli's rotate.php*
>>>
>>> ** *
>>>
>>> ** (but why? why possible use case is there for linking to *
>>>
>>> ** rotate.php?img=file.gif instead of straight to file.gif?)*
>>>
>>> **/*
>>>
>>> *$file_types = array( *
>>>
>>> *'gif' => 'image/gif',*
>>>
>>> *'jpg' => 'image/jpeg',*
>>>
>>> *'jpeg' => 'image/jpeg',*
>>>
>>> *'png' => 'image/png'*
>>>
>>> *) ;*
>>>
>>> *$regex = '/\.(' . implode('|',array_keys($file_types)) . ')$/i' ;*
>>>
>>> *$files = array() ;*
>>>
>>> *$directory = opendir(".");*
>>>
>>> *while ( FALSE !== ($file = readdir( $directory )) ) {*
>>>
>>> *if ( preg_match( $regex, $file ) ) {*
>>>
>>> *$files[] = $file ;*
>>>
>>> *}*
>>>
>>> *}*
>>>
>>> *if ( !empty( $files ) ) {*
>>>
>>> *$which = rand(0,sizeof($files)-1) ;*
>>>
>>> *if ( $file = file_get_contents( $files[$which] ) ) {*
>>>
>>> *$parts = explode('.',$files[$which]) ;*
>>>
>>> *$ext = strtolower($parts[sizeof($parts)-1]) ;*
>>>
>>> **
>>>
>>> *header( "Content-type: " . $file_types[$ext] ) ;*
>>>
>>> *header( "Expires: Wed, 29 Jan 1975 04:15:00 GMT" );*
>>>
>>> *header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );*
>>>
>>> *header( "Cache-Control: no-cache, must-revalidate" );*
>>>
>>> *header( "Pragma: no-cache" );*
>>>
>>> *print $file ;*
>>>
>>> **
>>>
>>> *}*
>>>
>>> *}*
>>>
>>> --
>>> [ Drupal support list | http://lists.drupal.org/ ]
>>>
>>
>>
>> --
>> [ Drupal support list | http://lists.drupal.org/ ]
>>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>



-- 
Cheers,
Amit Vyas
____________________________________________________________________________
____
Email  : amit.vyas at blisstering.com               Skype : vyasamit2004
Mobile : +91 993-040-1490                          Phone : +91-022
428-884-07
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110225/c4cee9eb/attachment-0001.html 


More information about the support mailing list