11
antifmradio
Re: random image in header? possable or no?

Quote:

mboyden wrote:
clear as mud?

clear as mud?


i guess not.
here is what i ended up with
i took the insert code and placed it in the header section of theme.html
then i went to just before that code still in theme.html
and pasted the other part of the code.

This is the way it layed out exactly
<img src="<{php}> echo getRndImgURL('headimages'); <{/php}>" alt="" width="730" height="150" /><br />
                <
img src="<{php}> echo getRndImgURL('headimages'); <{/php}>" alt="" width="730" height="150" />

but for some reason
when i goto my page
i see the header but NO images in it
i just see the box or table the header is supposed to sit in

nothing else on the page shows below the header
its all blank with its background color showing

12
mrphilong
Re: random image in header? possable or no?
  • 2008/12/4 5:13

  • mrphilong

  • Quite a regular

  • Posts: 351

  • Since: 2006/7/14


Have a look at this script

/*
By Matt Mullenweg > http://photomatt.net
Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
Latest version always at:
http://photomatt.net/scripts/randomimage
*/// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder '';

// Space seperated list of extensions, you probably won't have to change this.
$exts 'jpg jpeg png gif';

$files = array(); $i = -1// Initialize some variables
if ('' == $folder$folder './';

$handle opendir($folder);
$exts explode(' '$exts);
while (
false !== ($file readdir($handle))) {
foreach(
$exts as $ext) { // for each extension check the extension
if (preg_match('/.'.$ext.'$/i'$file$test)) { // faster than ereg, case insensitive
$files[] = $file// it’s good
++$i;
}
}
}
closedir($handle); // We’re not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand mt_rand(0$i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // Voila!
?>


Demo UcChau.Net

13
antifmradio
Re: random image in header? possable or no?

i completely get more confused with each answer on this
and its not you mboyden
forgive me
im really good at HTML and some PHP

but for some reason i am completely NOT getting this at all so hear me out

i need to place this
<img src="<{php}> echo getRndImgURL('random'); <{/php}>" alt="" width="158" height="116" />


in my header at the location where i want the images to show up

the folder where the images are located is called
RANDOM

the location of this folder is right now inside a specific theme folder
"geometric_red"

Now just before the code above i post pasted, i need to place this code

<{php}>
function 
getRndImgURL($path) { // Display Random Image from File Path
    
$i 0;
    
$dir = @opendir(XOOPS_ROOT_PATH.'/themes/random/'.$GLOBALS['xoopsConfig']['theme_set'].'/'.$path);
    while ( 
false !== ($filename readdir($dir)) ) {
        if ( 
preg_match("/(.gif|.jpg|.png)$/"$filename) ) { // image filter
            
$images[$i] = $filename;
            
$i++;
        }
    }
    
closedir($dir);
    
mt_srand( (double)microtime() * 1000000 );
    
$choice array_rand($images);
    return 
XOOPS_URL.'/themes/random/'.$GLOBALS['xoopsConfig']['theme_set'].'/'.$path.'/'.$images[$choice];
}
<{/
php}>



is this correct?
please see where the $dir is specified in the second code here.

Was i supposed to change it to match? or not.

Im looking at the code you pasted just now but im just no getting it
i have a code very similar to it and it works on another site ( not XOOPS ) that i administer for someone else.
its works and calls exactly the same way

create a subdirectory called " random "
in "random " place an index.php file with the code in it.
goto the page where you want to rotate images
call "index.php" using an "image source" function




the problem i am having doing that is
i cant for the life of me get my "theme.html" to call am image source in the header of this file

14
ghia
Re: random image in header? possable or no?
  • 2008/12/4 12:55

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


To make it less confusing take url images in stead of random.
<img src="<{php}> echo getRndImgURL('images'); <{/php}>" alt="" width="158" height="116" />

Create a directory /themes/random/geometric_red/images/ (for you: /themes/random/yourthemename/images/)and place there the images to be picked.

15
mboyden
Re: random image in header? possable or no?
  • 2008/12/4 14:20

  • mboyden

  • Moderator

  • Posts: 484

  • Since: 2005/3/9 1


Go back to my original code (without the
tag). Do not edit the original function - leave it exactly as is. This function when called allows you to pass the name of the subdirectory of images. What that does is allows you to have more than one set of randomly called images on your page. Each subdirectory will need to have the same size images for this to work, though.

The way this is designed, it is THEME-based (the assumption being that if you change themes you likely want to change images).

So, in your theme directory (in your case, geometric_red -- I've used this theme myself), make a subdirectory for your images (in your case, 'random', thus XOOPS_ROOT/themes/geometric_red/random). Place your images (all same size) in this subdirectory.

Then, make the call passing the name of the subdirectory in the call like this:



Notice that when calling the function, we pass the subdirectory path (inside the theme) of the images. Note, too, that if you have more than one set, you could pass a path, for instance if you have:
random/set1
random/set2
random/set3...
then the subdirectory passed when calling the function would be 'random/set1', 'random/set2', etc.

BTW, make sure you set the width and height to be the size of your pictures. The numbers used in the example I provided were for the particular placement I used.

Hopefully I've diluted those muddy waters some?
Pessimists see difficulty in opportunity; Optimists see opportunity in difficulty. --W Churchill

XOOPS: Latest | Debug | Hosting and Web Development

Login

Who's Online

428 user(s) are online (341 user(s) are browsing Support Forums)


Members: 0


Guests: 428


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits