4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: releasedj on February 07, 2003, 03:00:54 PM

Title: [Mod] Display random images on homepage, if no new images
Post by: releasedj on February 07, 2003, 03:00:54 PM
This little hack allows you to see random new images on the home page that fall within the cuttof limit, this makes the page look more active.

If there are no "new" images, it will display the newest images ordered by date.

At line 81 in index.php (with version 1.7), you will see the following code:

Code: [Select]
$num_new_images = $config['image_cells'];
$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").")
        ORDER BY i.image_date DESC
        LIMIT $num_new_images";

If you replace this code with:

Code: [Select]
$new_cutoff = time() - 60 * 60 * 24 * $config['new_cutoff'];
$num_new_images = $config['image_cells'];
$sql = "SELECT IF(i.image_date >= $new_cutoff,RAND()+1,1) as random_no, i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").")
        ORDER BY random_no DESC, i.image_date DESC
        LIMIT $num_new_images";

this should do it for you.

Regards,

Kelvin
Title: [Mod] Display random images on homepage, if no new images
Post by: uny on February 22, 2003, 11:14:13 PM
so, what if I want to have One Line of Static images, and one line of Random images? thanks for your help!
Title: [Mod] Display random images on homepage, if no new images
Post by: V@no on February 23, 2003, 12:55:34 AM
Quote from: uny
so, what if I want to have One Line of Static images, and one line of Random images? thanks for your help!

http://www.4homepages.de/forum/viewtopic.php?t=4259
Title: [Mod] Display random images on homepage, if no new images
Post by: toto1 on May 06, 2003, 04:59:02 PM
good very thk
Title: [Mod] Display random images on homepage, if no new images
Post by: www.girls-on-bikes.com on June 12, 2003, 03:38:39 AM
Hmm, I saw no changes with this.
Does it actually display random images, or does it display the 4 latest images, even if they fall off the "new" bandwagon?

Thanks
Title: [Mod] Display random images on homepage, if no new images
Post by: V@no on June 12, 2003, 03:43:41 AM
Quote from: www.girls-on-bikes.com
Hmm, I saw no changes with this.
Does it actually display random images, or does it display the 4 latest images, even if they fall off the "new" bandwagon?

yes, this will show random images on index.php from new images. But when no new images avalable, it will show "static" (not random) last added images, insteadof displaying "No new images" as another mod that randomize new images on home page.
Title: [Mod] Display random images on homepage, if no new images
Post by: www.girls-on-bikes.com on June 12, 2003, 03:44:36 AM
Oooooooooh, my bad, soowy  :oops:
And in that case, can we get the subject of this thread changed?
It does not accurately reflect what the mod does.
Thanks
Title: [Mod] Display random images on homepage, if no new images
Post by: www.girls-on-bikes.com on June 12, 2003, 03:52:06 AM
Call me a n00b, cause the only other randomizer I found was this:
http://www.4homepages.de/forum/viewtopic.php?t=1968

Which doesn't do crap if you don't have any new images (see link in sig).

 8O Linkify Me Cause I'm Blind  8O
Title: [Mod] Display random images on homepage, if no new images
Post by: V@no on June 12, 2003, 04:09:45 AM
yes, thats the mod. that one is older then this one for about 3 month ;)
Title: [Mod] Display random images on homepage, if no new images
Post by: www.girls-on-bikes.com on June 12, 2003, 04:13:04 AM
Is there a mod that exists that will display 4 random images if no new images exist?
Title: [Mod] Display random images on homepage, if no new images
Post by: V@no on June 12, 2003, 04:46:35 AM
hum...no
Title: [Mod] Display random images on homepage, if no new images
Post by: V@no on June 12, 2003, 04:59:28 AM
Quote from: V@no
hum...no

that answer made me look into the code... :lol:
replace:
Code: [Select]
       ORDER BY random_no DESC, i.image_date DESCwith:
Code: [Select]
       ORDER BY random_no DESC, RAND(), i.image_date DESC
Title: [Mod] Display random images on homepage, if no new images
Post by: www.girls-on-bikes.com on June 12, 2003, 06:05:41 AM
Thanks!  That works perfectly.
Title: [Mod] Display random images on homepage, if no new images
Post by: Apollo13 on June 16, 2003, 05:01:18 PM
well ia dd that mod two nice and short
Title: [Mod] Display random images on homepage, if no new images
Post by: PREACHER on June 24, 2003, 04:27:13 PM
Hey it realy works[/size] :lol:
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: police22 on April 25, 2005, 08:07:23 PM
..SNIP
At line 81 in index.php (with version 1.7), you will see the following code:
..SNIP
this should do it for you.
Regards,
Kelvin
So V@no, will this work with 1.7.1
gonna go ahead and try real quick but thought i should ask
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: police22 on April 25, 2005, 08:13:45 PM
..SNIP
At line 81 in index.php (with version 1.7), you will see the following code:
..SNIP
this should do it for you.
Regards,
Kelvin
So V@no, will this work with 1.7.1
gonna go ahead and try real quick but thought i should ask
Well.. i installed it.. have new images on there so cant test but it didn't error... Thanks
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: V@no on April 26, 2005, 12:28:30 AM
u can lower your "new images" timeout in the settings ;)
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: garett on July 10, 2005, 10:25:03 PM
that answer made me look into the code... :lol:
replace:
Code: [Select]
       ORDER BY random_no DESC, i.image_date DESCwith:
Code: [Select]
       ORDER BY random_no DESC, RAND(), i.image_date DESC

Do you know if there is a mod that do the same thing but with the categories (and sub-categories) and not with the homepage?
I mean if there is no image in a categorie, you display a line of random images from the subcategories.

It would makes the site more dynamic.

Title: Re: [Mod] Display random images on homepage, if no new images
Post by: egyptsons on December 11, 2005, 12:32:45 PM
nice work I will try it  8)
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: obmob01 on March 16, 2006, 02:24:52 AM
Oh, i added this to 1.7.2, seems to work fine.

Code: [Select]
$new_cutoff = time() - 60 * 60 * 24 * $config['new_cutoff'];
$num_new_images = $config['image_cells'];
$sql = "SELECT IF(i.image_date >= $new_cutoff,RAND()+1,1) as random_no, i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id NOT IN (".get_auth_cat_sql("auth_viewcat", "NOTIN").")
        ORDER BY random_no DESC, RAND(), i.image_date DESC
        LIMIT $num_new_images";
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: viper357 on March 25, 2006, 12:31:53 PM
hey thanks man, I also added it to 1.7.2 and it works great  :D
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Sopur on May 03, 2006, 05:02:39 PM
Quote from: V@no
hum...no
that answer made me look into the code... :lol:
replace:
Code: [Select]
        ORDER BY random_no DESC, i.image_date DESCwith:
Code: [Select]
        ORDER BY random_no DESC, RAND(), i.image_date DESC
Does this mean, ONLY if there are no NEW images, it will take some other random?
(Das heisst also, erst wenn es keine "neuen" Bilder mehr hat, wird aus allen ausgewählt?)
Regards
Sopur
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: V@no on May 04, 2006, 12:13:58 AM
Yes, if there are some new images they will be displayed in random order, but it there no new images, then it will show random images from entire gallery.
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Ch*yeuk on July 18, 2006, 11:08:05 PM
Hahah, awesome! Done it, and love it
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Fastian on September 03, 2006, 08:35:51 PM
This little hack allows you to see random new images on the home page that fall within the cuttof limit, this makes the page look more active.
Code: [Select]
$new_cutoff = time() - 60 * 60 * 24 * $config['new_cutoff'];
$num_new_images = $config['image_cells'];
$sql = "SELECT IF(i.image_date >= $new_cutoff,RAND()+1,1) as random_no, i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").")
        ORDER BY random_no DESC, i.image_date DESC
        LIMIT $num_new_images";

Is this possible to Exclude one category from this block of code ??
I dont want to show new/random images from One category
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: V@no on September 03, 2006, 08:48:08 PM
Add code in red in this line:[qcode]       WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").") AND i.cat_id NOT IN(1,2,3,4,5)
[/qcode]
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Fastian on September 03, 2006, 09:09:35 PM
Thankx V@no
You are The Guru  :D
Title: Randomize old images if there is no NEW for version 1.7.6 [MOD]
Post by: eXtremer on September 20, 2008, 01:02:17 PM
Hi all.
I've searched the forum and found only this : http://www.4homepages.de/forum/index.php?topic=4010.0
..but I can't integrate it in 1.7.6 version there is no such lines in index.php
Could someone give me another MOD ?
Help please.
Title: Re: Randomize old images if there is no NEW for version 1.7.6 [MOD]
Post by: budduke on September 20, 2008, 04:10:08 PM
The code changed a little, some brackets were added on the second line..
it is around line 106...
in version 1.7.6, it looks like this now
Code: [Select]
$num_new_images = $config['image_cells'];
$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id NOT IN (".get_auth_cat_sql("auth_viewcat", "NOTIN").")
        ORDER BY i.image_date DESC
        LIMIT $num_new_images";
replace this with what is in that mod and it should work for you...
Also, add the random to it so the same images will not show up all the time. look further down the mod topic to find the random addition
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: apnetz on January 28, 2010, 03:02:25 PM
Quote from: V@no
hum...no
that answer made me look into the code... :lol:
replace:
Code: [Select]
       ORDER BY random_no DESC, i.image_date DESCwith:
Code: [Select]
       ORDER BY random_no DESC, RAND(), i.image_date DESC

This does not work on 1.7.7, no new images appear at all.
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Hagen-Roderich on January 31, 2010, 02:28:29 PM
I have tryed this MOD, but dont get it to work. (4images Version 1.77 but index.php shows version 1.76)
Error:
An unexpected error occured. Please try again later.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /is/htdocs/47852/domainname/media/includes/db_mysql.php on line 116

After login as Admin the error is:

DB Error: Bad SQL Query: SELECT IF(i.image_date >= 1264340208,RAND()+1,1) as random_no, i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name, u.user_name FROM gallery_images i, gallery_categories c LEFT JOIN gallery_users u ON (u.user_id = i.user_id) WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (0, 264, 162, 132, 131, 130, 273, 252, 176, 150, 140, 108, 207, 219, 113, 275, 292, 257, 282, 261, 244, 255, 177, 144, 259, 122, 251, 191, 254, 186, 274, 142, 111, 204, 174, 272, 281, 283, 170, 136, 135, 237, 284, 296, 212, 217, 250, 234, 171, 208, 193, 265, 216, 262, 240, 209, 158, 256, 277, 178, 278, 247, 114, 201, 157, 290, 145, 196, 214, 185, 197, 198, 222, 260, 203, 258, 263, 295, 106, 133, 235, 141, 206, 143, 233, 189, 112, 169, 210, 179, 146, 276, 168, 269, 246, 194, 159, 213, 253, 215, 238, 243, 288, 123, 172, 151, 134, 109, 202, 220, 232, 271, 115, 279, 245, 124, 293, 267, 164, 147, 192, 116, 249, 205, 165, 125, 137, 218, 160, 231, 195, 211, 184, 118, 294, 161, 242, 163, 280, 200, 270, 199, 166, 138, 126, 149, 180, 190, 230, 285, 239, 268, 181, 156, 297, 119, 167, 139, 127, 148, 229, 183, 120, 152, 236, 286, 128, 107, 228, 298, 287, 182, 187, 153, 129, 227, 121, 154, 289, 226, 155, 291, 225, 224, 223) ORDER BY random_no DESC, i.image_date DESC LIMIT 3
Unknown column 'i.user_id' in 'on clause'

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /is/htdocs/47852/domainname/media/includes/db_mysql.php on line 116

No Images are showend

What went wrong?
http://www.4homepages.de/forum/index.php?topic=22668.0? MySQL is V 5.0.32
"If your 4images is newer then v1.7.1 and you still get these errors, then you must have installed a mod that is not MySQL v5 compatible." Does thise mean this MOD is not MySQL v5 compatible? If so how to change the code to work with MySQL v5?
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Nicky on January 31, 2010, 11:12:21 PM
change
Code: [Select]
       FROM ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
to

Code: [Select]
       FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)
.. look now...
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Hagen-Roderich on February 01, 2010, 07:58:49 PM
Thank you works perfectly.

Next question:
How to make "Neue Bilder" only be showed if there are new images?
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: arabcine on June 02, 2010, 10:03:52 PM
this work
http://www.4homepages.de/forum/index.php?topic=4010.msg64771#msg64771


but it's show to me 4 images how i can set it 6 pic ?
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: V@no on June 03, 2010, 02:35:09 PM
FAQ -> How can I show more new images on home page? (http://www.4homepages.de/forum/index.php?topic=8946.0)
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: dunyakupasi on June 12, 2010, 01:59:45 AM
This does not work on 1.7.7
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: arabcine on June 12, 2010, 02:26:38 AM
This does not work on 1.7.7

try this its work
http://www.4homepages.de/forum/index.php?topic=4010.msg64771#msg64771
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Hagen-Roderich on June 15, 2010, 08:39:47 AM
This does not work on 1.7.7

Whats your MySQL version, you are useing?

MySQL 5?
If so, try: http://www.4homepages.de/forum/index.php?topic=4010.msg145087#msg145087
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: MrAndrew on July 05, 2011, 06:56:55 PM
ORDER BY random_no DESC, RAND(), i.image_hits DESC

This rondomize my new images sorted by hits "image_hits" query too... How to randomize only random_no???
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: brez on November 11, 2011, 06:32:47 PM
Does not work with 1.7.10

Quote
DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name, u.user_name FROM (4images_images i, 4images_categories c) LEFT JOIN 4images_users u ON (u.user_id = i.user_id) WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id NOT IN (0) ORDER BY random_no DESC, RAND(), i.image_date DESC LIMIT 8
Unknown column 'random_no' in 'order clause'

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/irishavs/public_html/includes/db_mysql.php on line 116
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Rembrandt on November 11, 2011, 07:06:34 PM
Does not work with 1.7.10
.....Unknown column 'random_no' in 'order clause'

you have no column 'random_no' in your DB

this works
http://www.4homepages.de/forum/index.php?topic=4010.msg64771#msg64771
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: V@no on November 11, 2011, 07:50:04 PM
Does not work with 1.7.10
It works, you just made a mistake on the first line of the code you were supposed to replace.
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: brez on November 11, 2011, 07:56:17 PM
Thanks Rembrandt it works alright but......
I had 8 images showing to fill the homepage, now i am reduced to 4 again.
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Rembrandt on November 11, 2011, 08:06:46 PM
do you want 8 images only on home.html?
search in the code:
LIMIT $num_new_images";

replace:
LIMIT 8";


mfg Andi
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: brez on November 11, 2011, 08:15:30 PM
Absolutely Perfect!
Thanks!
Title: Re: [Mod] Display random images on homepage, if no new images
Post by: Rembrandt on November 11, 2011, 08:25:17 PM
no problem  :D