We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5274
    • 177 Posts
    The Front Range Mountain Bike Patrol site http://frmbp.org/ has been converted after a few years on e107 to a MODx site. The "Notices" link at the bottom provides info on the tools used.
      • 7231
      • 4,205 Posts
      Looks and works good. Well done.

      How did you handle the random image feature?
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 19132
        • 199 Posts
        Nice work. Good to see someone just up the hill from us. New to MODx but not CMS’s.

        How did you do the random image? I need to find a way to do random quotes.
          MySQL: 5.0.45
          PHP: 5.2.6
          Linux 2.6.9-023stab048.6-enterprise #1
          cURL enabled
          PDO enabled
          FFox Apple 3.6.8
          Firebug DIS-abled
          • 5136
          • 16 Posts
          maybe this function smiley
          http://www.php.net/array_rand

            • 27708 MODX Staff
            • 2,502 Posts
            The random image looks to be done with MaxiGallery. It is fairly easy to do. I think that you should try something else as it would be overkill to try to refactor MG to do just quotes.
              Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I use this for random quotes:
              $resourceparent = $quoteid;  // the folder that contains quote documents 
              $output = '';  // initialise the quote variable 
              $resource = $modx->getActiveChildren($resourceparent,'createdon', 'DESC', $fields='content');
              $limit=count($resource);
              if($limit<1) { 
                 $output .= "No entries found.<br />";
                 return $output; 
              }
              $random = (rand(1, $limit) - 1); 
              $output .= $resource[$random]['content']; // get a random quote
              return $output;

              The "quoteid" gets set as a parameter in the snippet call.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 5274
                • 177 Posts
                Quote from: smashingred at Nov 18, 2007, 08:44 AM

                The random image looks to be done with MaxiGallery. It is fairly easy to do. I think that you should try something else as it would be overkill to try to refactor MG to do just quotes.

                Yes, I used Maxigallery for the random images. The front page call is:

                [!MaxiGallery? &display=`embedded` &embedtype=`slimbox` &gal_query_ids=`99` &order_by=`random` &limit=`1`!]
                


                There are multiple galleries and each is managed through a separate page that remains hidden unless the web user is signed in. The call on the page for the front page images is:

                [!MaxiGallery? &manage_gallery=`99` &max_pic_size=`640` &max_thumb_size=`150` &thumb_use_dropshadow=`1`!]
                


                EDIT: I almost forgot. The banners on the top in the header area are also random. They use a custom chunk, snippet and placeholders that were designed using this as the starting point:

                <?php
                
                /*****
                Random banners
                
                (C) 2007 NZ's Finest
                www.nzsfinest.com
                
                HOW TO USE -
                Edit the information below (http://www.website.com,image.png, etc).
                The format is <url>,<image>
                
                Or add in new banners by copying the text
                "http://www.website.com,image.png",
                and pasting it on a new line above
                "http://www.website.com,image.png",
                
                Then include it on your website by using the code:
                include("banners.php");
                *****/
                
                $banners = array(
                "http://www.website.com,image.png",
                "http://www.example.com,images/banner.jpg",
                );
                
                /*****
                ATTENTION -
                DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
                *****/
                
                $randnum = rand(0, count($banners) - 1); // Choose a random banner
                $exploded = explode(",", $banners[$randnum]); // Separate chosen banner by ,
                
                $url = $exploded[0]; // Grab the URL for the banner
                $img = $exploded[1]; // Grab the image for the banner
                
                // Display the banner
                echo "<a href=\"$url\">";
                echo "<img src=\"$img\" border=\"0\" />";
                echo "</a>";
                
                ?>
                
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I used a style block in the template with this line:
                  background: url(assets/images/top/[!RandomImage!]) no-repeat top right;

                  and the RandomImage snippet:
                  / get images from bg image directory
                  if ($handle = opendir('./assets/images/top')) {
                      $i = 1;
                      while (false !== ($file = readdir($handle))) {
                          if (substr($file, 0, 1) != ".") {
                           $images[$i] = $file;
                           $i++;  
                          }       
                      }
                      closedir($handle);
                  } 
                  
                  //return a random filename
                  $randomimage = rand(1, count($images));
                  return $images[$randomimage]; 
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 13754
                    • 3 Posts
                    Quote from: Chuck at Nov 18, 2007, 12:46 AM

                    The "Notices" link at the bottom provides info on the tools used.

                    I don’t mean to be over-picky, especially since it’s my first post ever, but don’t you mean JavaScript Framework: MooTools? wink
                      • 5274
                      • 177 Posts
                      Quote from: jbrudolf at Nov 20, 2007, 03:35 PM

                      ...don’t you mean JavaScript Framework: MooTools? wink

                      Yes I do and thanks for catching that.