Posted on: 04/28/09 07:56am
By: tgc
I want to do a random image block with selected images which then link to certain URLs.
I found one script which works on a regular page on my server, have a look
here.
But when I add this (and the corresponding phpblock) as a function to lib-custom like this:
Text Formatted Code
function phpblock_random()
{
$file_type = ".jpg";
$text_file_type = ".txt";
$image_folder = "images";
$handle = opendir("/xxx/x/duvide.com/public_html/random/$image_folder");
while ($file = readdir($handle))
$names[count($names)] = $file;
closedir($handle);
sort($names);
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"){
$names1[$tempvar]=$names[$i];$tempvar++;
}
}
$random = mt_rand(1, $tempvar);
$image_name = $random . $file_type;
$text_name = $random . $text_file_type;
}
// end random
The block is not showing at all, not even an error message.
Any ideas?
Thank you/Frank
Re: phpblock not showing
Posted on: 04/28/09 09:23am
By: suprsidr
need to return something?
-s
Re: phpblock not showing
Posted on: 04/28/09 09:30am
By: suprsidr
Geeklog has 2 image gallery plugins each of which have imageblock functionality BTW.
-s
Re: phpblock not showing
Posted on: 04/28/09 09:36am
By: tgc
if you are in the know, please tell me the code I need in order to get it running. I am not a php guy, in case you have not noticed.
I know there are image galleries but their random blocks don't do what I need.
Thank you
Re: phpblock not showing
Posted on: 04/28/09 09:49am
By: Dirk
A PHP block should return the HTML that Geeklog will then display in the block. However, the above code doesn't really do anything from what I can see. So it's not only the missing return statement - it's not clear what that code is supposed to do in the first place ...
bye, Dirk
Re: phpblock not showing
Posted on: 04/28/09 09:53am
By: tgc
it should do what it does on this
link but in a block in geeklog:
with each refresh it changes the images randomly. Very simple I would think.
Thanks for your help/Frank
Re: phpblock not showing
Posted on: 04/28/09 09:55am
By: suprsidr
Re: phpblock not showing
Posted on: 04/28/09 10:05am
By: tgc
thank you s but I am not using Gallery 2 right now...
Frank
Re: phpblock not showing
Posted on: 04/28/09 12:52pm
By: suprsidr
Oops sorry almost forgot about you.
try:
Text Formatted Code
function phpblock_random_images() {
global $_CONF;
$image_directory = '/images/';
$link = $_CONF['site_url'];
$pattern = ".jpg$";
$files = array ();
$display = '';
if ($handle = opendir($_CONF['path_html'].$image_directory)) {
while ($file = readdir($handle)) {
if (eregi($pattern, $file)) {
$files[] = $file;
}
}
shuffle($files);
$file = $_CONF['path_html'].$image_directory.$files[0];
list ($width, $height, $type, $attr) = getimagesize($file);
$display .= '<a href="'.$link.'"><img src="'.$_CONF['site_url']
.$image_directory.$files[0].'" '.$attr
.' alt="'.$files[0].'" title="'.$files[0].'"></a>';
closedir($handle);
}
return $display;
}
-s
Re: phpblock not showing
Posted on: 04/28/09 01:07pm
By: tgc
Thank you for your effort -s.
But this is not the script I need to incorporate into the block.
Why is my script working on a normal page but not in the geeklog blog? That is would I would like to solve.
Frank
Re: phpblock not showing
Posted on: 04/28/09 01:53pm
By: tgc
the code for the linked page is like this:
Text Formatted Code
<?php include "/xxx/x/duvide.com/public_html/random/random.php";
echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";
include "$image_folder/$text_name"; ?>
like I said, I am not the php guy, maybe something needs to be added to the code for the block?
Frank
Re: phpblock not showing
Posted on: 04/29/09 07:00am
By: tgc
no ideas how I can integrate this to my block?
Thanks/Frank
Re: phpblock not showing
Posted on: 04/29/09 07:46am
By: suprsidr
My example works..... still.
-s
Re: phpblock not showing
Posted on: 04/30/09 12:16pm
By: tgc
Hi -s, it works but not like I need it to work. I want only certain images displayed randomly linking to a certain URL and I want a caption. My
standalone script[*1] does this and I just would like to have it in a block. Is this too much to ask for
Thanks/Frank