Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » silverstriping a site with random pictures

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1 2 3
Go to End
Author Topic: 8524 Views
  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    silverstriping a site with random pictures Link to this post

    Hi Folk

    have a look at www.cloud9russell.co.nz. I would like SilverStripe this. It should be pretty straight forward (although I am a complete novice), but I would like to know how to do the images. I can easily do this in PHP (as you can see), but how would i go about it in Silverstripe (just tell me the general area I should be looking at and how to work it). Basically my question is: I have a php file, how can I silverstripe it?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: silverstriping a site with random pictures Link to this post

    This tutorial here is what you'll be needing: http://doc.silverstripe.com/doku.php?id=tutorial:2-extending-a-basic-site

    It explains how to create image uploaders for pages within the CMS. More specifically, it's the 'Adding a staff section' portion of the tutorial you'll be most interested in.

    If you're looking to get a random image instead of a fixed one per page, then you could add the images to a directory inside assets/banners or similar (in the same directory level as sapphire and cms), then create a function as you would normally in any PHP implementation to fetch this directory's contents using scandir or similar, then shuffle the array around.

    The banners directory inside assets can be maintained by the CMS using the Files & Images section. The SilverStripe admin can upload the image files directly into the banner directory itself which gets added to the shuffle.

    If you haven't already done so I'd recommend running through the tutorials to see how SilverStripe works.

    Cheers,
    Sean

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: silverstriping a site with random pictures Link to this post

    Hi Sean

    Thanks a million

    That is plenty to go by. I had a quick look at the tutorials and I will look at them in more depth now.

    Thanks again

    Nicolaas

  • karibe
    Avatar
    Community Member
    56 Posts

    Re: silverstriping a site with random pictures Link to this post

    Hello
    I had same problem and my tip is, in Page_Controller

       public function RandomImage( $strLeftDirName )
       {
          if ( !is_string( $strLeftDirName ) )
          {
             return false;
          }
          $left_dir = DataObject::get_one("Folder", "Name = \"$strLeftDirName\"");
          $randImg = ( $left_dir->ID ) ? DataObject::get_one("Image", "ParentID = $left_dir->ID", true, "RAND()" ) : false;
          return $randImg->Filename;
       }

    And in template $RandomImage(page_left) where page_left is directory name where I have proper images.
    Works fine and is very flexible

  • bubbles
    Avatar
    Community Member
    1 Post

    Re: silverstriping a site with random pictures Link to this post

    That function works great, Thanx

  • stooni
    Avatar
    Community Member
    89 Posts

    Re: silverstriping a site with random pictures Link to this post

    can you tell me, to implement random Image in sidebar from gallery,
    the function in mysite\code\Page.php and the call in the
    \templates\Includes\SideBar.SS.

    can you help me thanks!

    Stooni----

  • stooni
    Avatar
    Community Member
    89 Posts

    Re: silverstriping a site with random pictures Link to this post

    Can you help me where i must do these?????

    In the Sidbar.ss or in templates\Page.ss and must i scribe

       <image src="<?php $RandomImage(gallery); ?>" /> these way or these
    <image src="<?php $RandomImage('gallery'); ?>" /> or these
       <?php $RandomImage(gallery); ?>

    Thanks for help

    Stooni
       

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: silverstriping a site with random pictures Link to this post

    Stooni,

    Make sure to thoroughly go through the tutorials. The SS templating system does not work PHP code. You'd have to create a function in your page which returns the list of random images (or single image) ... Then you can call it by implementing a <% control %> in your template.

    8524 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.