Author Topic: [Mod] Display random images on homepage, if no new images  (Read 67955 times)

0 Members and 1 Guest are viewing this topic.

Offline releasedj

  • Pre-Newbie
  • Posts: 2
    • View Profile
[Mod] Display random images on homepage, if no new images
« 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
« Last Edit: July 23, 2011, 10:02:04 PM by Rembrandt »

Offline uny

  • Newbie
  • *
  • Posts: 46
    • View Profile
[Mod] Display random images on homepage, if no new images
« Reply #1 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!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Display random images on homepage, if no new images
« Reply #2 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
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline toto1

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
    • http://www.gifanimer.com
[Mod] Display random images on homepage, if no new images
« Reply #3 on: May 06, 2003, 04:59:02 PM »
good very thk

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[Mod] Display random images on homepage, if no new images
« Reply #4 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

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Display random images on homepage, if no new images
« Reply #5 on: June 12, 2003, 03:43:41 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?

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.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[Mod] Display random images on homepage, if no new images
« Reply #6 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

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[Mod] Display random images on homepage, if no new images
« Reply #7 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

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Display random images on homepage, if no new images
« Reply #8 on: June 12, 2003, 04:09:45 AM »
yes, thats the mod. that one is older then this one for about 3 month ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[Mod] Display random images on homepage, if no new images
« Reply #9 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?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Display random images on homepage, if no new images
« Reply #10 on: June 12, 2003, 04:46:35 AM »
hum...no
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Display random images on homepage, if no new images
« Reply #11 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
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline www.girls-on-bikes.com

  • Full Member
  • ***
  • Posts: 145
    • View Profile
    • http://www.girls-on-bikes.com/
[Mod] Display random images on homepage, if no new images
« Reply #12 on: June 12, 2003, 06:05:41 AM »
Thanks!  That works perfectly.

Offline Apollo13

  • Addicted member
  • ******
  • Posts: 1.093
    • View Profile
[Mod] Display random images on homepage, if no new images
« Reply #13 on: June 16, 2003, 05:01:18 PM »
well ia dd that mod two nice and short

Offline PREACHER

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • http://www.desktopart.de
[Mod] Display random images on homepage, if no new images
« Reply #14 on: June 24, 2003, 04:27:13 PM »
Hey it realy works[/size] :lol:
Schreibfehler sind beabsichtigt und dienen der allgemeinen Belustigung.