Gossamer Forum
Home : Products : Links 2.0 : Customization :

Links numbers on subcategories?

Quote Reply
Links numbers on subcategories?
Hello,
I'm setting up my Links 2.0 page and I would need to show a layout like this:

Category 1 (XX links)
Subcategory 1 (XX links)
Subcategory 2 (XX links)

Category 2 (XX links)

... and so on.

I've already applied the Subcat mod 2 that you can find here: http://cgi-resource.co.uk/pages/subcat2.shtml, so now on the home page the subcategories are listed beneath the main categories. But now I'm looking a way to show also the number of links beside each subcategory.
Does anybody have a clue on how can I do that?

Any help would be greatly appreciated!

Last edited by:

Nightjar: Feb 27, 2003, 12:37 AM
Quote Reply
Re: [Nightjar] Links numbers on subcategories? In reply to
try searching for category numbers in this forum. I believe this has been dealt with.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Links numbers on subcategories? In reply to
I spent the last three hours searching for a viable solution posted elsewhere on this forum. Unfortunately, I didn't find anything related to the subcategories; only mods for categories numbers...

Still looking for a solutionUnsure
Quote Reply
Re: [Nightjar] Links numbers on subcategories? In reply to
Its been a long time since I've played with Links 2, so this may, or may not work Tongue

What happens if you add;

Code:
my ($subcats_id) = @{$category{$subcat}}[0];

my ($output, $sep, $hit_count, $id);
$sep = "|";
open (DB, "$db_category_name") or &cgierr ("unable to open category database: $db_category_name. Reason: $!");
LINE: while (<DB>) {
/^#/ and next LINE;
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.

my @values = &split_decode($_);

if ($values[4] == $subcats_id) { $hit_count++; }

}
close DB;

below;

Code:
my ($subcats) = @{$category{$subcat}}[8];

Then replace;

Code:
$subcats .= qq|</a><br>|;

with;

Code:
$subcats .= qq| ($hit_count)</a><br>|;

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Links numbers on subcategories? In reply to
Hello Andy,
As I'm not a Links 2 expert, I only found that I should add the 3rd code snippet you suggested to the site_html.pl file. But I really don't know where I should add the first two snippets (the ones beginning with my ($subcats_id) = and my ($subcats) =

Can you please give me a hint?
Blush
Quote Reply
Re: [Nightjar] Links numbers on subcategories? In reply to
OK, as I'm using templates, I added the code to the site_html_templates.pl file, but the number that appears beside the subcategories is just the total number of categories in the database, not the links contained in each subcategory.
Maybe I've done something wrong, but right now I'm still stucked... Frown

Last edited by:

Nightjar: Feb 28, 2003, 10:28 AM
Quote Reply
Re: [Nightjar] Links numbers on subcategories? In reply to
Ok, found it.
On my site_html_templates.pl file I have applied both those modifications:

* Subcat Mod 2 by GB Resources http://cgi-resource.co.uk/pages/subcat2.shtml
* Non English Text Mod by Matthias Berndt http://www.gossamer-threads.com/...urces/jump.cgi?ID=28

And this is the code:

sub site_html_print_cat {
# --------------------------------------------------------
# This routine determines how the list of categories will look.
# We now use a table to split the category name up into two columns.
# For each category you can use the following variables:
#
# $url : The URL to go to that category
# $category_name : The category name with _ and / removed.
# $category_descriptions{$subcat}: The category description (if any).
# $numlinks : The number of links inside that category (and subcategories).
# $mod : The newest link inside of that category.
#
my ($subcats_id) = @{$category{$subcat}}[0];

my ($output, $sep, $hit_count, $id);
$sep = "|";
open (DB, "$db_category_name") or &cgierr ("unable to open category database: $db_category_name. Reason: $!");
LINE: while (<DB>) {
/^#/ and next LINE;
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.

my @values = &split_decode($_);

if ($values[5] == $subcats_id) { $hit_count++; }

}
close DB;

my ($subcats) = @{$category{$subcat}}[9];

my (@subcat) = @_;
# ***************************************** nonenglish modification - begin ****************
# my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i, $nonenglish);
# ***************************************** nonenglish modification - end ******************
my ($half) = int (($#subcat+2) / 2);

# Print Header.
$output = qq|<div class="margin"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n|;

foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];
my ($subcats) = @{$category{$subcat}}[9];

@subcats = split(/\Q$db_delim\E/, $subcats); $subcats = "";
foreach $scat (@subcats) {
$subcats .= qq|<a class="link" href="$build_root_url/|;
$subcats .= &urlencode($scat);
$subcats .= qq|/$build_index">|;

if ($scat =~ m,.*/([^/]+)$,) { $subcats .= &build_clean($1);}
else {
$subcats .= &build_clean($scat);
}

$subcats .= qq| ($hit_count)</a><br>|;
}

# ***************************************** nonenglish modification - begin ****************
($nonenglish) = @{$category{$subcat}}[8];

# ***************************************** nonenglish modification - end ******************

# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
# ***************************************** nonenglish modification - begin ****************
# if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
if ($nonenglish eq "") {
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }
}
else {
$category_name = &build_last_title_mb($nonenglish);
}
# ***************************************** nonenglish modification - end ******************
$numlinks = $stats{"$subcat"}[0];
$mod = $stats{"$subcat"}[1];

# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
if ($i == $half) {
$output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;

# 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|<dd><span class="descript">$subcats</span></dd>|;
$output .= qq|</dl>|;
}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}
Quote Reply
Re: [Nightjar] Links numbers on subcategories? In reply to
make the following changes to correct the alignment of the cats/subcats

Code:
# 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|<dd><span class="descript">$subcats</span></dd></dl>|;
}


They don't exist in your current site_html_print_cat


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."