Author Topic: {random_cat_image} how can I have another one  (Read 4587 times)

0 Members and 1 Guest are viewing this topic.

Offline webbug

  • Newbie
  • *
  • Posts: 33
    • View Profile
{random_cat_image} how can I have another one
« on: December 24, 2008, 12:31:26 PM »
ok here what i want: I need to have 2 random images in the details page.  A good workaround to this is to include another {random_cat_image}

But

when i have {random_cat_image}{random_cat_image}, it shows the same image.

Now

I thought of having {random_cat_image2} which calls random_cat_image2.html

where can I do this?

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
Re: {random_cat_image} how can I have another one
« Reply #1 on: December 24, 2008, 03:37:02 PM »
Since random images is the smallest bottleneck of the script (aka it has most impact on the site's performance), 4images caches random images for each category that improves performance if more then one random image needed, that's why it doesn't matter how many times you tried get a random image for the same category (on same page) it will be the same. Other words, any changes to this will degrease your site performance.

In details.php (and/or in categories.php) find:
$random_cat_image = (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0) ? "" get_random_image($cat_id);

Insert below:if (!defined("SHOW_RANDOM_IMAGE") || SHOW_RANDOM_IMAGE != 0)
{
  
$random_image_cache get_random_image_cache();
  
$random_cat_image2 get_random_image($cat_id);
  
$site_template->register_vars("random_cat_image2"$random_cat_image2);
}


Use {random_cat_image2} tag
« Last Edit: January 06, 2009, 03:59:02 PM by V@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 webbug

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: {random_cat_image} how can I have another one
« Reply #2 on: January 06, 2009, 10:43:52 AM »
nothing happens and no error msg.

Offline webbug

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: {random_cat_image} how can I have another one
« Reply #3 on: January 06, 2009, 10:53:41 AM »
I did it this way

$random_cat_image = (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0) ? "" : get_random_image($cat_id);
$random_cat_image2 = (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0) ? "" : get_random_image($cat_id);
$site_template->register_vars("random_cat_image2", $random_cat_image2);
$site_template->register_vars("random_cat_image", $random_cat_image);
unset($random_cat_image);
unset($random_cat_image2);


it works now but both show the same pic  :oops:

What to do now? or is there any other way to use 2 random pics inside details page with less performance impact?

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
Re: {random_cat_image} how can I have another one
« Reply #4 on: January 06, 2009, 03:59:44 PM »
Sorry, my mistake, I've updated my post above. Should work now.
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)