1 keljem Jan 15, 2008 12:03
3 afwas Jan 23, 2008 12:41
For an not related project I made this:
<?php
/**
* Genererate random number and pick random foto's from a folder.
*
*/
function genRandomArray( $min, $max, $num )
{
$result = array();
$count = 0;
$currentnum = 0;
while(count($result) < $num)
{
$currentnum = rand($min, $max);
if (!in_array($currentnum, $result))
{
$result[$count] = $currentnum;
$count++;
}
}
return $result;
};
$handle = opendir( '../images/' ); // the folder with pics
while ( false !== ( $file = readdir( $handle )))
{
if ( $file!= "." && $file != ".." ) {
$picArray[] = $file;
}
};
closedir( $handle );
$k = 0;
$aantalFotos = count( $picArray );
$aantalFotos = $aantalFotos - 1; // Stupid arrays
$rrand = genRandomArray(0, $aantalFotos, 1); //Now number of pics is 1
/* for($i = 1; $i <= 2; $i++) */ //So no need for this loop
{
$pNumber = $rrand[$k];
$picture[] = $picArray[$pNumber];
$k++;
}
?>
<?php
//Show the picture
$random_pic = '../images/'.$picture[0];
?>
<img src="<?php echo $random_pic ?>" alt="Random Picture" />
Put this code in a file randompic.php, put the file on the server.
Go to backoffice, add a freeHTML widget to the sidebar, edit it and point it to the randompic.php file.
Simply put an arbitrary number of pictures in the ../images/ folder and it should work.
Questions?
*edit*
This is not going to work in a freeHTML widget or some one must know how to call a php file in the widget. Probably you'll have to put the code in the skin. I will follow up on this post in a few hours time.
4 keljem Jan 23, 2008 13:02
Hi Afwas,
Thanks for your help with this, its very good of you :)
I will check back later to see if it can be done, thanks again for all you help.
Gosh, this is a nice forum :)
Gz
5 edb Jan 23, 2008 13:16
PHP in the Free HTML widget works?
6 keljem Jan 23, 2008 13:23
Thanks,
I trust when Afwas said 'Point it to the php file' he meant like this ?
(in the free html in the widget I put)
<img src="randompic.php" alt="Random Picture" title="Random Picture" />
Is this correct please ?
If it is then it doesn't seem to be working unless I have messed up somewhere ?
Gz
7 edb Jan 23, 2008 13:34
Okay that might work. If not the same trick can be done with javascript. Not the best solution imaginable though so let's hope using a php file as the img src works.
8 john Jan 23, 2008 13:41
Maybe ....
<img src="<?php echo $random_pic ?>" alt="Random Picture" />
9 keljem Jan 23, 2008 17:57
No luck guys with this one, sorry.
Thanks for your help everyone though :)
Gz
10 afwas Jan 23, 2008 21:48
No this is not going to work the way I hoped. The code is OK, see http://www.blog.hemminga.net/randompic.php I am now converting the code into a widget.
11 afwas Jan 24, 2008 03:02
Random Picture plugin version 0.1
I have made a new topic in the Plugin section of the forum: [url=http://forums.b2evolution.net/viewtopic.php?t=14100&start=0&postdays=0&postorder=asc&highlight=][2.3] Random Picture plugin (widget)[/url].
Yes, the plugin is ready.
12 keljem Jan 24, 2008 10:13
Good Morning Afwas :)
Thank you very much indeed, I cant believe that you have gone to so much trouble on my behalf. It is very good of you and I think this will be a top plugin download for everyone. THANK YOU.
Could you have a look at the link for the download of the plugin on the post please, I can't seem to get the file.
Thanks very much, it looks really good from the screen shots and just what I was looking for.
:) :) :) :) :) :) :) :) :) :)
Gz
13 john Jan 24, 2008 10:17
@Gary, just get rid of the " and the , at the end of the active download link in that post
14 keljem Jan 24, 2008 10:32
Cheers John,
I didn't see that ;)
Gz
15 afwas Jan 24, 2008 10:33
I fixed the link
16 keljem Jan 24, 2008 10:48
Nice one, thanks again for all your help Afwas.
I just hope I pick up some knowledge over the next few years to help someone in the future like you helped me. Although coding isn't my strongest point and php goes straight over my head.
Your a star :)
Gz
17 keljem Jan 24, 2008 10:50
WOW, just installed it and it worked first time a treat.
Thanks again Afwas, just one glitch (if I dare mention it) It doesnt seem to like to work in IE :-/
Not that I care as I never use Internet Exploder 8|
Gz
18 afwas Jan 24, 2008 11:24
keljem wrote:
Thanks again Afwas, just one glitch (if I dare mention it) It doesnt seem to like to work in IE :-/ z
Fixed, see the other topic.
Glad you like it.
19 keljem Jan 24, 2008 11:29
* at the risk of looking stupid *
Thanks, Sorry which other topic do you mean ?
Gz ;)
20 afwas Jan 24, 2008 11:31
[url=http://forums.b2evolution.net/viewtopic.php?t=14100&start=0&postdays=0&postorder=asc&highlight=][2.3] Random Picture plugin (widget)[/url].
21 keljem Jan 24, 2008 11:44
Fantastic, thanks again.
Its just what I wanted ;)
I owe you a beer :P
Gz
Forgot to say, that this could maybe use images in an original post
or
from a separate folder on the server.
Cheers
Gz