Author Topic: random thumbnail on categories  (Read 8848 times)

0 Members and 1 Guest are viewing this topic.

Offline ctranter

  • Newbie
  • *
  • Posts: 20
    • View Profile
random thumbnail on categories
« on: July 23, 2005, 08:03:06 PM »
I have used:

{if random_cat_image_file}<a href="{cat_url}"><img src="{random_cat_image_file}" border="0"></a>{endif random_cat_image_file}

to display a random thumbnail for the categorys and sub categories. But some of my categories don;t contain any images - they only act as holders. Is it possible to then retreive a random thumbnail from one of the sub categories, if the main categoy doesnt have any images in it?

Offline ctranter

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: random thumbnail on categories
« Reply #1 on: August 17, 2005, 10:24:16 AM »
anyone, please?

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 thumbnail on categories
« Reply #2 on: August 17, 2005, 02:55:16 PM »
the topic was lost, and I could find only first page of it.

1.
Open /includes/functions.php
Find:
Code: [Select]
function get_random_imageAdd after (below):
Code: [Select]
global $cat_parent_cache;

1.2
Find:
Code: [Select]
    $category_id = $cat_id;Add after:
Code: [Select]
    $subcat_ids = array();
    $subcats = get_subcat_ids($cat_id, $cat_id, $cat_parent_cache);
    if (is_array($subcats) && is_array($subcats[$cat_id])) {
      array_push($subcats[$cat_id], $cat_id);
      global $cat_cache;
      foreach ($subcats[$cat_id] as $key => $val)
      {
        if (!$cat_cache[$val]['num_images'])
        {
          unset($subcats[$cat_id][$key]);
        }
      }
      $key = array_rand($subcats[$cat_id]);
      $category_id = $subcats[$cat_id][$key];
      $cat_id = $category_id;
    }



1.3
Find:
Code: [Select]
  global $subcat_ids;
Replace with:
Code: [Select]
  global $subcat_ids, $cat_cache;


1.4
Find:
Code: [Select]
    if (check_permission("auth_viewcat", $val)) {
      $subcat_ids[$cat_id][] = $val;
      get_subcat_ids($val, $cat_id, $cat_parent_cache);
    }

Replace with:
Code: [Select]
    if (check_permission("auth_viewcat", $val) && (!$field || ($field && $cat_cache[$val][$field]))) {
      $subcat_ids[$cat_id][] = $val;
      get_subcat_ids($val, $cat_id, $cat_parent_cache);
    }



NOTE: your php version must be v4.2 or newer.


P.S. attached google cache page of the original post
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 ctranter

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: random thumbnail on categories
« Reply #3 on: August 17, 2005, 03:24:40 PM »
Thanks very much!

Offline Zyga

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: random thumbnail on categories
« Reply #4 on: December 14, 2005, 05:45:37 PM »
hmmmmm
uncomented line
{if random_cat_image_file}<a href="{cat_url}"><img src="{random_cat_image_file}" border="0"></a>{endif random_cat_image_file}

shows me no results  - what should I change ?

and second question - not exactly in this topic but similliar
How can I "turn on" random pictures under category list (like new on home page)
I post this question in discusion/req board and V@no  send me to this topic but its not exactly what I need

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 thumbnail on categories
« Reply #5 on: December 15, 2005, 12:37:54 AM »
hmmmmm
uncomented line
{if random_cat_image_file}<a href="{cat_url}"><img src="{random_cat_image_file}" border="0"></a>{endif random_cat_image_file}

shows me no results - what should I change ?
if it doesnt show you anyting even if the category has images in it, then probably this feature is turned off in inclues/constants.php (find SHOW_RANDOM_CAT_IMAGE)

How can I "turn on" random pictures under category list (like new on home page)
I post this question in discusion/req board and V@no send me to this topic but its not exactly what I need
Do, you want to display category images randomly? not sorted?
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 Zyga

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: random thumbnail on categories
« Reply #6 on: December 15, 2005, 05:54:17 PM »
it could be sorted (sort mod work great)
i just need to put something under the subcategory list

when category is empty (only holds subcategory) it looks really... hmmmm empty ;)