by 300SMG
7 replies
  • WEB DESIGN
  • |
I'm looking to use a random image display as a 'featured coupon' section on a side bar. Is there a plugin, php script or something else where I can designate a folder to pull images from and have them randomly display as the page is refreshed?
#image #random
  • Profile picture of the author Brandon Tanner
    All you need is a few lines of PHP to do that. First, paste this code at the very top of the page (before the opening <HTML> tag)...

    <?php
    $path = "images/";
    $images = scandir($path);
    $i = rand(2, sizeof($images)-1);
    ?>


    Don't forget to change the part in red to the actual path of your "images" folder (if different).

    Then wherever you want the image to appear on the page, do this...

    <img src="<?php echo $path . $images[$i]; ?>" />

    Be sure to save this page with a .php extension, and you should be good to go!
    Signature

    {{ DiscussionBoard.errors[7150054].message }}
  • Profile picture of the author 300SMG
    Thank you Brandon, what about using this in a sidebar of a wordpress site?
    Signature

    Don't focus on the money - focus on the plan!

    {{ DiscussionBoard.errors[7151346].message }}
    • Profile picture of the author Brandon Tanner
      Originally Posted by 300SMG View Post

      Thank you Brandon, what about using this in a sidebar of a wordpress site?
      Sorry... Wordpress really isn't my thing, so I couldn't tell you how to do that. The demo code above is for regular websites.
      Signature

      {{ DiscussionBoard.errors[7151419].message }}
  • Profile picture of the author 300SMG
    Thank you. I appreciate it. It will go to good use on a static site for sure.
    Signature

    Don't focus on the money - focus on the plan!

    {{ DiscussionBoard.errors[7156993].message }}
    • Profile picture of the author bhmseoservices
      Originally Posted by 300SMG View Post

      Thank you. I appreciate it. It will go to good use on a static site for sure.
      For wordpress there might be a way.
      There are plugins that allow you to put a PHP field inside your widgets.
      The one I use is exephp or inphp - but there are many out there.
      That's how I get contact form 7 on my sidebars.
      {{ DiscussionBoard.errors[7157004].message }}
      • Profile picture of the author bheadrick
        "Advanced text widget" will allow PHP
        THer'es several other plugins that do this as well.
        {{ DiscussionBoard.errors[7158059].message }}
        • Profile picture of the author webpeon
          Originally Posted by bheadrick View Post

          "Advanced text widget" will allow PHP
          THer'es several other plugins that do this as well.
          adcodes widget would do this but you'd have to insert each image manually...

          <img src="your1stimg.jpg"></img>
          <!--rotate-->
          <img src="your2ndimg.jpg"></img>
          <!--rotate-->
          <img src="your3rdimg.jpg"></img>
          <!--rotate-->
          <img src="your3rdimg.jpg"></img>
          <!--rotate-->
          Signature
          Web 2 Mobile
          The Future of The Web
          {{ DiscussionBoard.errors[7158460].message }}

Trending Topics