Submit Your Article Forum Rules

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: need help on wordpress customization

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    2

    need help on wordpress customization

    I need to take 3 pictures and have them rotate each time the page is refreshed. So if somebody goes to the website 3 times they might see 4 different pictures in the top header area.

    Any plugin or code??
    Last edited by imrul; 04-24-2012 at 01:45 AM.

  2. #2
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,772
    Perhaps the OP could help us with a little more information, in particular, which theme are you using? Thesis, for instance, already does this.

    Need more info...

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    2
    I made a theme by myself using artisteer theme creator .. and my client want this now ... by the way what is OP ?? thanks a lot 4 your reply

  4. #4
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,772
    Aside: OP can mean either 'opening post' or 'opening poster', depending upon context. In the above context, it would mean the latter of the two.

    If you created the theme yourself, then you must have some PHP skill, one would assume? If this is the case then one simply needs to create a folder just off the root, or the root of the folder your page is contained within, and give it simple, understandable name. Into that folder, drop as many pre-sized images as you wish, then run a 'discovery script' over the directory, shuffle the results, and serve out the top result tagged and ready to go.

    Refer to the example at the end of the PHP Loops thread, except in your case, the PHP would be either in the main page, or pulled into the page as an include, and only point to the folder containing the pictures. Once the array is assembled and shuffled, one would split it after the first element, then generate the image tag.
    Last edited by weegillis; 04-24-2012 at 03:23 PM. Reason: photo > folder / link to example thread

  5. #5
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,772
    It would doubtless be better to let one discover and learn, but to save you some time and confusion, I'll lay out the example as it would apply to your situation:

    PHP Code:
    <?php
     $folder 
    "images";
     
    $cwd getcwd();
     
    $chdir($folder);
     
    $img_handle = array();
     if (
    $handle opendir('.') ) {
      while (
    false !== ($file readdir($handle) )) {
       if (
    stristr($file'.jpg')) {
        
    $img_handle[] = $file;
       };
      };
      
    closedir($handle);
     };
     
    chdir($cwd);
     
    shuffle($img_handle);
     
    $img array_shift($img_handle); // pulls from top of array, rather than bottom (array_pop())

    // $img at this point is also an array
    // Since there is only one row, the loop following will only cycle through once.
    // now simply generate your tag and echo it in the appropriate container, and all is well.

     
    foreach($img as $key => $src) {
      
    $istristr($src".");
      
    $j $i 4;
      
    $k substr($src0$j);
      
    $str "<img src=\"$src\" width=\"200\" height=\"200\" alt=\"$k\">";
     };
     
    ?>
    The image width and height are fixed, so no need to poll them. Just hard code the appropriate values in to the tag.

    Not tested, so there may be some debugging or tweaking necessary. This is only an example.
    Last edited by weegillis; 04-24-2012 at 04:39 PM. Reason: format

  6. #6
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,772
    ERROR:

    I left out an important detail: the path to the image files.
    PHP Code:
      $src $folder "/" $src;
      
    $str "<img src=\"$src\" width=\"200\" height=\"200\" alt=\"$k\">"

  7. #7
    Junior Member mikeewart's Avatar
    Join Date
    Jan 2004
    Posts
    17
    imrul - You might want to spend some time going thru the Artisteer forum too. Sometimes you can find solutions to working with their themes there.

    I am not a WP person, but I use Artisteer w/ Joomla and have found that some things require manually going into the final product generated by Artisteer and making modifications.

    Weegillis - FYI - He used a wysiwyg editor to generate the theme. No coding is involved what so ever.

  8. #8
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,772
    Quote Originally Posted by mikeewart View Post
    Weegillis - FYI - He used a wysiwyg editor to generate the theme. No coding is involved what so ever.
    I get that, now. Thanks. Guess the above is lost on him, then. It will still plug in to any page, though as you suggest, the theme probably has a range of plug-ins for this purpose.

  9. #9
    Junior Member
    Join Date
    Nov 2011
    Location
    Melbourne, Australia
    Posts
    3

    Post Simple code that I use to display a different image each time the page is reloaded

    I used this code to do almost what you're looking for.
    If you know a little about php this will help a lot.

    Replace code within a php widget or in the theme header section of your theme.
    Actually there are many plugins that would do this too but this is fairly simple and light on the server.

    An example of this is on the home page of energyforhome dot com the banner above the content is driven from a widget.

    Replace the strings below with the code for your image and url.

    PHP Code:
    <?php 
    $image 
    =  (rand(15));
    switch (
    $image)
    {
     case 
    1:echo "HTML CODE for Image 1"; break;
     case 
    2:echo "HTML CODE for Image 1"; break;
     case 
    3:echo "HTML CODE for Image 1"; break;
     case 
    4:echo "HTML CODE for Image 1"; break;
     case 
    5:echo "HTML CODE for Image 1"; break;
    }
    ?>

    Goodluck!

  10. #10
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,772
    Quote Originally Posted by ozdogan View Post
    PHP Code:
    <?php 
    $image 
    =  (rand(15));
    switch (
    $image)
    {
     case 
    1:echo "HTML CODE for Image 1"; break;
     case 
    2:echo "HTML CODE for Image 1"; break;
     case 
    3:echo "HTML CODE for Image 1"; break;
     case 
    4:echo "HTML CODE for Image 1"; break;
     case 
    5:echo "HTML CODE for Image 1"; break;
    }
    ?>
    The biggest advantage that the above example (my post) has over this one is that it doesn't require any maintenance. The photo folder can have as many pictures in it as one want to place there. The polling script discovers them, and supplies information about them to the generation script. The photos can even be in a range of folders that are pointed to by day of week, category, or other identifier, and then the photo for the page taken from that group.

    As we can see, any change in photos for this example, will require editing of the HTML CODE within the page. This, imho, is just asking for trouble (as in typo's, etc.).

  11. The following user agrees with weegillis:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •