Author Topic: Hide categories with no images  (Read 12964 times)

0 Members and 1 Guest are viewing this topic.

Offline shain

  • Newbie
  • *
  • Posts: 22
    • View Profile
Hide categories with no images
« on: March 27, 2005, 10:03:12 AM »
Greetings everyone,

I have a quick question. If you have a look at: http://www.snaip.com/wildhorizons/categories.php?cat_id=97 , you will see that there are many categories with zero (0) images in them. Is there a way I can hide those categories? Then they will automatically appear when there's new images in them? I tried to look at functions.php in includes, but it is looking far way too complicated.

TheOracle

  • Guest
Re: Hide categories with no images
« Reply #1 on: March 27, 2005, 07:17:52 PM »
I like this request. :)

Make a backup of your includes/functions.php file. Then,

find :

Quote

    $site_template->register_vars(array(
      "cat_id" => $category_id,
      "cat_name" => $cat_cache[$category_id]['cat_name'],
      "cat_description" => $cat_cache[$category_id]['cat_description'],
      "cat_hits" => $cat_cache[$category_id]['cat_hits'],
      "cat_is_new" => $is_new,
      "lang_new" => $lang['new'],
      "sub_cats" => get_subcategories($category_id),
      "cat_url" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$category_id),
      "random_cat_image_file" => $random_cat_image_file,
      "num_images" => $num_images
    ));
   
    $categories .= $site_template->parse_template("category_bit");
    $count++;
    $count2++;
    $categories .= "</td>\n</tr>\n";


replace with :

Code: [Select]

    if ($categories) {
 
    $site_template->register_vars(array(
      "cat_id" => $category_id,
      "cat_name" => $cat_cache[$category_id]['cat_name'],
      "cat_description" => $cat_cache[$category_id]['cat_description'],
      "cat_hits" => $cat_cache[$category_id]['cat_hits'],
      "cat_is_new" => $is_new,
      "lang_new" => $lang['new'],
      "sub_cats" => get_subcategories($category_id),
      "cat_url" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$category_id),
      "random_cat_image_file" => $random_cat_image_file,
      "num_images" => $num_images
    ));
   
    $categories .= $site_template->parse_template("category_bit");
    $count++;
    $count2++;
    $categories .= "</td>\n</tr>\n";
   
    } ####### End of if statement.


I tried it with a single category (on both statement regarding ' existing & unexisting ' categories). Both matches perfectly. Hopefully, this is what you're looking for. :D

If not, you can always replace the backup file you made. ;)

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Re: Hide categories with no images
« Reply #2 on: March 30, 2005, 05:19:01 PM »
hhhmmm,

doesn´t work for subcats.....   :(
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

TheOracle

  • Guest
Re: Hide categories with no images
« Reply #3 on: May 05, 2005, 05:16:08 AM »
Sure,

replace this part :

Quote

if ($categories) {
 
    $site_template->register_vars(array(
      "cat_id" => $category_id,
      "cat_name" => $cat_cache[$category_id]['cat_name'],
      "cat_description" => $cat_cache[$category_id]['cat_description'],
      "cat_hits" => $cat_cache[$category_id]['cat_hits'],
      "cat_is_new" => $is_new,
      "lang_new" => $lang['new'],
      "sub_cats" => get_subcategories($category_id),
      "cat_url" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$category_id),
      "random_cat_image_file" => $random_cat_image_file,
      "num_images" => $num_images
    ));
   
    $categories .= $site_template->parse_template("category_bit");
    $count++;
    $count2++;
    $categories .= "</td>\n</tr>\n";
   
    } ####### End of if statement.


with this one :

Code: [Select]
   
    if ($categories && function_exists('get_subcategories') && $num_images >= 1) {
 
    $site_template->register_vars(array(
      "cat_id" => $category_id,
      "cat_name" => $cat_cache[$category_id]['cat_name'],
      "cat_description" => $cat_cache[$category_id]['cat_description'],
      "cat_hits" => $cat_cache[$category_id]['cat_hits'],
      "cat_is_new" => $is_new,
      "lang_new" => $lang['new'],
      "sub_cats" => get_subcategories($category_id),
      "cat_url" => $site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$category_id),
      "random_cat_image_file" => $random_cat_image_file,
      "num_images" => $num_images
    ));
   
    $categories .= $site_template->parse_template("category_bit");
    $count++;
    $count2++;
    $categories .= "</td>\n</tr>\n";
   
    } ####### End of if statement.


;)

Again - excellent idea. This even reduce my layout's height size for unused categories ' and ' subcategories usage so that, if they're empty, they won't show up. :D

Offline shain

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Hide categories with no images
« Reply #4 on: July 01, 2005, 05:18:24 PM »
TheOracle,

Thanks a lot for this one! :) 

- Shain

TheOracle

  • Guest
Re: Hide categories with no images
« Reply #5 on: July 02, 2005, 04:22:41 AM »
No problem. I liked this request very much. :D

Offline Gulper

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Hide categories with no images
« Reply #6 on: July 04, 2005, 10:51:38 AM »
:) This is awesome! :)
Just one problem... empty categories are not visible anymore... but their space, where they have been, is still there... I mean, when I had a category overview with 9 categories and 5 of them were empty.... there are then 4 visible categories left... but the places, where the 5 empty categories were are still occupied.... so it looks very chaotic now...
Is there a way to reorder the category display, so that there are no empty spaces anymore?
..sorry for my bad english...

TheOracle

  • Guest
Re: Hide categories with no images
« Reply #7 on: July 04, 2005, 01:31:01 PM »
Quote

their space, where they have been, is still there...


Sounds like the table heading would need to be re-structured in two separated categories statement from the same action. The problem is, the $visible_cat_cache is being used from a single ' foreach ' statement in that function section. Let me play with it a little bit longer and I will post the results once I found the way to do this.

Sounds like fun. ;)

The good news is, the first part is done. 8)

Offline Gulper

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Hide categories with no images
« Reply #8 on: July 06, 2005, 07:09:57 PM »
Would be more than great if you can solve this! :)
Thanx in advance.....

TheOracle

  • Guest
Re: Hide categories with no images
« Reply #9 on: July 06, 2005, 07:18:51 PM »
Update:

I have solved it but, the problem is, I'm encountering some difficulties to maintain the category layout from the functions. However, the good news is, I have successfully removed the empty URL titles entirely from the category box as requested above.

That said, the categories needs to be called from two seperated basis from the same general function. It is a little bit hard to code as, hopefully, the results will be posted soon. ;)

Offline om6acw

  • Full Member
  • ***
  • Posts: 187
    • View Profile
    • My Animal's World
Re: Hide categories with no images
« Reply #10 on: February 18, 2007, 05:59:42 PM »
Somebody try this on 1.7.4?

I got this error

Code: [Select]
Parse error: syntax error, unexpected ';', expecting T_PAAMAYIM_NEKUDOTAYIM or '(' in /home/myanimw/public_html/includes/template.php(101) : eval()'d code on line 7
thanks

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: Hide categories with no images
« Reply #11 on: February 18, 2007, 07:23:56 PM »
please check your category_bit.html
i think you find the error there.

Offline om6acw

  • Full Member
  • ***
  • Posts: 187
    • View Profile
    • My Animal's World
Re: Hide categories with no images
« Reply #12 on: February 18, 2007, 08:09:38 PM »
please check your category_bit.html
i think you find the error there.

Ups I am soo stupid :) I have this problem long time ago and I'm completly forgot about category_bit.html