Recent Topics

1 Jan 15, 2008 12:03    

My b2evolution Version: 1.10.x

Does anyone know if there is a plugin for v2.3 to add a random photo to the sidebar in a widget with free html ?

Thanks
Gz ;)

2 Jan 23, 2008 11:56

Forgot to say, that this could maybe use images in an original post

or

from a separate folder on the server.

Cheers
Gz

3 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 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 Jan 23, 2008 13:16

PHP in the Free HTML widget works?

6 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 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 Jan 23, 2008 13:41

Maybe ....

<img src="<?php echo $random_pic ?>" alt="Random Picture" />

9 Jan 23, 2008 17:57

No luck guys with this one, sorry.
Thanks for your help everyone though :)

Gz

12 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 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 Jan 24, 2008 10:32

Cheers John,
I didn't see that ;)

Gz

16 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 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 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 Jan 24, 2008 11:29

* at the risk of looking stupid *

Thanks, Sorry which other topic do you mean ?

Gz ;)

21 Jan 24, 2008 11:44

Fantastic, thanks again.
Its just what I wanted ;)
I owe you a beer :P

Gz


Form is loading...