4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: alinford on February 14, 2003, 07:13:02 AM

Title: Image Count for Subcategory on Main Page
Post by: alinford on February 14, 2003, 07:13:02 AM
Is there any way to show the image totals in each subcategory while on the main page?
Title: Image Count for Subcategory on Main Page
Post by: Jan on February 15, 2003, 11:44:46 AM
Just copy {total_images} to the template categories.html

Jan
Title: Subcategory image count
Post by: alinford on February 16, 2003, 03:56:45 AM
That seems to give me the total of all images, not the total next to each subcategory.
Title: Image Count for Subcategory on Main Page
Post by: Jan on February 16, 2003, 09:26:09 AM
Ok, did not understand you correctly. But what do you mean exactly? You see the image count behind each category name.

Jan
Title: Image Count for Subcategory on Main Page
Post by: helluvaguy on February 16, 2003, 02:44:43 PM
I guess he wants to see the number of every subcategory that is displayed on the index page.
Like
Title: Yes...
Post by: alinford on February 16, 2003, 07:41:30 PM
You are a helluvaguy, that is exactly what I am looking for.
Title: Image Count for Subcategory on Main Page
Post by: V@no on February 16, 2003, 08:20:38 PM
Open /includes/functions.php
Find:
Code: [Select]
     $sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".$cat_cache[$subcat_id]['cat_name']."</a>";

Replace with:
Code: [Select]
     $sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".$cat_cache[$subcat_id]['cat_name']."</a> (".$cat_cache[$subcat_id]['num_images'].")";
Title: Thanks!
Post by: alinford on February 16, 2003, 10:54:11 PM
Thanks!
I had messed around with this for a few days and could not get it right.
I have a family site, http://linford.net
I have 4images integrated with Geeklog and this little change was somthing I needed.
Title: Re: Thanks!
Post by: heiko on February 20, 2003, 10:51:30 AM
Hi !


Ich habe da ein Problem,

Zwar bekomme ich jetzt auf der Hauptseite die Anzahl der Bilder in den Sub-Kategorien gezeigt, aber irgendwie stimmt der Zähler nicht.

Beispiel:

Musik (55)
      ---- LP´s (0)
      ---- Singles (0)
      ---- DVD (33)

Hier wird  (0) angezeigt obwohl z.B. 18 Bilder in der Kategorie LP´s vorhanden sind.


Irgendeine Idee woran das liegt ????


Liebe Grüße

Heiko
Title: Code Above
Post by: alinford on February 23, 2003, 10:52:47 PM
This is confusing, so you may need to read it more than once.
Is there any way that it can show the subcategory total + the total of all subcategories of the subcategory?

Somthing like this:
Title: Re: Code Above
Post by: V@no on February 23, 2003, 10:59:29 PM
Quote from: alinford

What the above is showing in the () is this:
Subcategory 1 (33) = 1(11) 1.a(7) + 1.a.1(5) + 1.b(10)
Subcategory 2 (24) = 2(0) + 2.a(24)
Subcategory 3 (14) = 3(14)

actualy that how it works...isnt it? atleast for me.
Title: Not for me
Post by: alinford on February 23, 2003, 11:28:19 PM
On the main page it shows like this for me:

Title: num_images
Post by: alinford on March 10, 2003, 10:13:13 PM
With the script above, I can now see num_images on index.php for each category as well as each immediate subdirectory.  num_images for Category shows the total images for the category, including all subdirectories.  The problem with the code above that adds num_images for the subdirectories only shows the image total for that subdirectory.  I would like it to show the total for the subdirectory and any subdirectories inside that subdirectory.
Any ideas?
Title: Image Count for Subcategory on Main Page
Post by: jengwen on May 22, 2003, 06:39:50 PM
Has anyone figured this out yet?  I am having the same problem.  I created a subcategory and then several subcategories under that.  My total for the main subcategory is 0, since all the images are in the subcategory under that.  For example:

Category:           Zoo Special Events (5)
Subcategory:             Egg Day (5)
Subcategory:             Migratory Bird Day (0)
Sub-Subcategory:             Games (15)
Sub-Subcategory:             Art Show (20)

This is very confusing, because only the main and subcategory show up in the main categories page, so it looks like there are no images under Migratory Bird Day, when there are actually 35.  The user doesn't know to click on it and look for the subcategories since it says there are 0 images.

If this cannot be solved, is there an easy way to show more levels of subcategory on the main category list?
Title: Re: Image Count for Subcategory on Main Page
Post by: Jasi on March 28, 2009, 01:31:32 PM
THX - Danke für diesen kleinen (little) MOD  :wink: Funktioniert bei mir in der V.1.7.6 perfekt!

Working perfect in/on V1.7.6

LG euer Jasi
Title: Re: Image Count for Subcategory on Main Page
Post by: Sebas Bonito on July 14, 2009, 03:30:07 PM
Has anyone figured this out yet?  I am having the same problem.  I created a subcategory and then several subcategories under that.  My total for the main subcategory is 0, since all the images are in the subcategory under that.  For example:

Category:           Zoo Special Events (5)
Subcategory:             Egg Day (5)
Subcategory:             Migratory Bird Day (0)
Sub-Subcategory:             Games (15)
Sub-Subcategory:             Art Show (20)

This is very confusing, because only the main and subcategory show up in the main categories page, so it looks like there are no images under Migratory Bird Day, when there are actually 35.  The user doesn't know to click on it and look for the subcategories since it says there are 0 images.

If this cannot be solved, is there an easy way to show more levels of subcategory on the main category list?

+++PUSH+++  :D

For the meanwhile I help me out with a trick:
REPLACE the whole $sub_cat_list Line with the following...

Code: [Select]
if ($cat_cache[$subcat_id]['num_images'] == 0) {
  $anzahl = "";
  }
  else {
  $anzahl = " (".format_text($cat_cache[$subcat_id]['num_images']).")";
  }
      $sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".format_text($cat_cache[$subcat_id]['cat_name'], 2)."</a>".$anzahl."";

It's not the best, but now it shows nothing, if there is really no content inside the subcategory OR if there is the 0-Bug.
Otherwise it will print out (5) for example.
Title: Re: Image Count for Subcategory on Main Page
Post by: cc on June 17, 2011, 11:11:02 AM
I know this is a very old thread, but it looks like no-one has solved this issue? So I decided to share what I did to implement a way of showing counts for a category hierarchy that includes the total images in subcategories. However, I found that it increased the number of SQL statements executed per page from around 25 to over 800, thus slowing down my pages. This was for a hierarchy of 163 categories up to 4 levels deep.

It involves a recursive function that starts from the top level and for each category finds all of its children, and all of its children's children, and so on, to build up a subcategory list for each category, which is then used to query the image table to get the total hierarchy counts.

I put the recursive function in functions.php and call it from globals.php to update the cat_cache with the results. I had then to put a fix into page_header.php otherwise the total_images value will double/triple/etc count the images in subcategories.

However because of the performance hit I decided to implement this in a different way which works for my site but may not be appropriate for other sites (I use my site as a way of distributing my catwalk fashion images to publishing clients, so I am the only person who uploads images and I normally do this in bulk via ftp). I made a plugin that does the same recursive hierarchy count but stores the results in a new field added to the categories table for each category. The population of cat_cache in globals.php is now just a single query to retrieve these values. Every time I do a bulk upload I run this plugin.

HTH,
Rob