Gossamer Forum
Home : Products : Links 2.0 : Customization :

Category Counts for Links in Sub-Categories

Quote Reply
Category Counts for Links in Sub-Categories
After having read all the posts related to link counts in categories and sub-categories, I was unable to find an answer to my question...or at least I think I wans't able to (I got lost in some of the technical jargon).

I am seeking the modification necessary to make the number of links I have in subcategories show up in the categories count regardless of whether I have any links directly in the categories list. For example:

Category A has 4 links and no subcategories so I get "Category A (4)"

Category B has 0 links but 3 subcategories which have 0, 1 and 6 links in them respectively so I get "Category B (0)"

How do I get category B to show as "Category B (7)" to account for the 7 links in the subcategories so Category B doesn't look like it is empty when you are at the top of the heirarchy.

If this question was posted earlier and I misread the answer, can some one point in the direction of which thread I should be reading?
Quote Reply
Re: [giznet] Category Counts for Links in Sub-Categories In reply to
Links 2 out of the box will show the number of sublinks in subcategories at the category level.

In other words, it is designed to show exactly what you are wanting but apparently not getting.

Have you made any changes? specifically to the site_html_print_cat routine in the site_html_templates.pl file?


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Category Counts for Links in Sub-Categories In reply to
Hello Gene,

Thanks for the reply. I made the following changes to that section to change the way the table looks. Could you please advise on which part I messed up when I made these changes? Thanks again for all your help!

Out of the Box:
$output = qq|<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;

Modifications:
$output = qq|<div align="center"><center><table width="90%" border="0" cellspacing="0" cellpadding="0" style="font-family: Verdana, Georgia, Arial; font-size: 8pt"><tr><td class="catlist" valign="top">\n|;

Out of the Box:
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;

Modifications:
if ($i == $half) {
$output .= qq|</td><td width="10"></td><td class="catlist" valign="top">\n|;

Out of the Box:
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);

Modifications:
$output .= qq|<sup class="new"><b><font color="#990033">new</font></b></sup>| if (&days_old($mod) < $db_new_cutoff);

Out of the Box:
$output .= "</td></tr></table></div>\n";

Modifications:
$output .= "</td></tr></table></center></div>\n";
Quote Reply
Re: [giznet] Category Counts for Links in Sub-Categories In reply to
This is from site-html_templates.pl, the part in red is what calls the count.

# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Category Counts for Links in Sub-Categories In reply to
Hello,

Got it. I checked the code you posted against the code I had. I made no change to the line that has ($numlinks) in it. Only to the parts I posted earlier. Is it possible that I am missing something small like a comma or a quote mark?

Thanks for your help!
Quote Reply
Re: [giznet] Category Counts for Links in Sub-Categories In reply to
Have you made any changes beside what you posted? In that file or in nph-build.pl?


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Category Counts for Links in Sub-Categories In reply to
Not that I have found. Perhaps I am not looking in the right place? Here is what I have in the nph-build file:

sub build_stats {
# --------------------------------------------------------
# This routine does a lot of the messy work. It builds globally accessible
# arrays of new_links and cool_links. It finds out how many links are in each
# category, and whether a category contains a new/modified link.

my (@values, $category, $cat, @alt_categories, @categorylist, $depth, $i, $cat);
my $staggered_mode = shift || undef;

open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name. Reason: $!");
LINE: while (<DB>) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp;
@values = &split_decode ($_);
$category = $values[$db_category];

# Add the link to the list of links.
push (@{$links{$category}}, @values) if (!$staggered_mode);
$grand_total++;

# Add the link to the alternate categories as well.
if (defined $db_alt) {
@alt_categories = split(/\Q$db_delim\E/, $values[$db_alt]);
foreach (@alt_categories) {
push (@{$links{$_}}, @values);
}
}

# Add the link to the list of new links if it is new.
push (@{$new_links{$category}}, @values) if ($values[$db_isnew] eq "Yes");

# Add the link to the list of cool links if it is popular.
push (@{$cool_links{$category}}, @values) if ($values[$db_ispop] eq "Yes");

# This adds one to the total of each category above the current category.
# We have to caluclate the affect of the link on each alt category as well as the main.
foreach $cat ($category, @alt_categories) {

# Calculate the stats: the number of links and the newest link.
@categorylist = split (/\//, $cat);
$depth = $#categorylist;

# This adds one to the total of each category above the current category,
# and also marks any above categories new, if this link is new.
for $i (0 .. $depth) {
$stats{$cat}[0]++;
if ((!$stats{$cat}[1]) || &compare_dates($values[$db_modified], $stats{$cat}[1])) {
$stats{$cat}[1] = $values[$db_modified];
}
pop (@categorylist);
$cat = join("/", @categorylist);
}
}
}
close DB;

# Now we have to sort the links and categories..
if (!$staggered_mode) {
foreach $link ( keys %links ) {
@{$links{$link}} = &build_sorthit (@{$links{$link}});
}
foreach $cat ( keys %subcategories ) {
@{$subcategories{$cat}} = sort @{$subcategories{$cat}};
}
}
$grand_total ||= 0;
}