Welcome to Geeklog Saturday, May 25 2013 @ 10:54 AM EDT
|
||||||||
![]() |
Forum Index > Extensions > Cool Hacks |
New Topic
|
Post Reply
|
Here's the code for showing a Random Image (4images) |
|||
| Anonymous: Lacy |
|
|||||
|
|
Add the following code to lib-custom.php (at the bottom - right before the ?>
PHP Formatted Code // RANDOM IMAGE FUNCTIONfunction phpblock_rand4image() { global $_CONF, $_USER, $_TABLES; $imgdir = "photos"; $title_limit = 30; $dscp_limit = 50; // DATABASE $rand_sql = DB_query("SELECT image_id,cat_id,image_name,image_description,image_thumb_file FROM 4images_images WHERE (image_thumb_file!='')ORDER BY RAND(NOW()) LIMIT 1"); $num = DB_numRows($rand_sql); if ($num == 0) { $rand .= '<br/><center>No images exist yet!</center><br/>'; } else { $A = DB_fetchArray($rand_sql); $album = DB_getItem("4images_categories",cat_name,"cat_id=$A[cat_id]"); if(strlen ($A['image_name']) > $title_limit){ $A['image_name'] = substr($A['image_name'], 0, $title_limit); $A['image_name'] .= ".."; } $rand .='<table width="98%"><td width="100%">'; $rand .='<center><a href="' .$_CONF['site_url']. '/' .$imgdir. '/details.php?image_id=' .$A['image_id']. '">'; $rand .='<img src="' .$_CONF['site_url']. '/' .$imgdir. '/data/thumbnails/' .$A['cat_id']. '/' .$A['image_thumb_file']. '" alt="' .$A['image_name']. '" style="border: 1 solid #000000;"><br>'; $rand .=$A['image_name']; $rand .='</a></center>'; $rand .='<br>Album: <a href="' .$_CONF['site_url']. '/' .$imgdir. '/categories.php?cat_id=' .$A['cat_id']. '">' .$album. '</a>'; $rand .='</td></table>'; return $rand; } } Now - create a new block. Type - PHP Block. Block Function - phpblock_rand4image You're all set! |
|||||
|
||||||
| Anonymous: Lacy |
|
|||||
|
|
Oh and change
$imgdir = "photos"; to whatever directory you have 4images installed in. I have mine installed in the photos folder .. therefore I put PHOTOS there. Later! |
|||||
|
||||||
| samstone |
|
|||||
![]() ![]() ![]() ![]() ![]() Full Member ![]() Status: offline ![]() Registered: 09/29/02 Posts: 820 |
Are you talking about 4image with GL1.3.11?
|
|||||
|
||||||
| Anonymous: Lacy |
|
|||||
|
|
I have it working with two versions - 1.3.10 and 1.3.9sr1. I haven't tested it out in other versions.
(I'm still working on getting 1.3.10 to fully integrate with 4images. The coe has changed and the integration hack doesn't work completely. But you don't have to have it integrated for this to work.) |
|||||
|
||||||
| deesh123 |
|
|||||
![]() ![]() ![]() ![]() ![]() Junior ![]() Status: offline ![]() Registered: 01/04/05 Posts: 22 |
For some dumb reason when I integrated 4images with GL, I put my 4images directory inside of another directory.
So my address to my photo album iis www.mysite.com/mypics/4images/index.php. Everything worked fine up until when I tried to apply the code for showing a random image. Since I have an extra folder, the random image code sends the user to http://www.mysite.com/public_html/gallery/details.php?image_id=8 instead of http://www.mysite.com/mypics/4images/details.php?image_id=8 What is the best way to alter the code to work with my extra directory? |
|||||
|
||||||
| deesh123 |
|
|||||
![]() ![]() ![]() ![]() ![]() Junior ![]() Status: offline ![]() Registered: 01/04/05 Posts: 22 |
||||||
|
||||||
| Content generated in: 0.41 seconds |
|
|
|