Gossamer Forum
Home : Products : Links 2.0 : Customization :

SubCat Mod Number of Links in subcats

Quote Reply
SubCat Mod Number of Links in subcats
Hi

I am using the Subcat mod like Yahoo version 2, Widgetz version, I would like the number of links to be displayed beside each subcat, I know it can be done and I know it was in these boards about a year ago but I can't find it any help would be appreciated

Thanks

DavyC


I have tried $numlinks in site_html_templates.pl but that gives the number of links in that category will I have to define a new scalar to calculate the links in the sub cateories?

Quote Reply
Re: SubCat Mod Number of Links in subcats In reply to
Hi

I am trying to use the Yahoo type Sub Categories v2, I did not get any mods made to the nph-build.cgi in relation to this but the sub categories appear however I am trying to get the number of links in the sub categories to also appear I have serched the foum and cannot find anything here is what I mean

Computer (32)
Hardware (12) Software (12) Other (8)

I beleive I need to modify site_html_templates.pl

sub site_html_print_cat {

here is what I have

my (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);
my ($half) = int (($#subcat+2) / 2);

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

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

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

# 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><font face="verdana" size=2><a href="$url">$category_name</a></strong> $icao <small class="numlinks">($numlinks)</small> |;
# $output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
my $days_old = &days_old($mod);
if ($days_old <= 2) { $output .= qq| $new_1|; }
elsif ($days_old <= 7) { $output .= qq| $new_3|; }
elsif ($days_old <= 14) { $output .= qq| $new_7|; }
$output .= qq|</dt>|;
if ($#{$subcategories{$subcat}} >= 0 && $description =~ /^SUB.*/) {
$v = 0;
$sub_length = "";
$output .= qq|<font face="Verdana,Sans-Serif" size="1">|;
foreach $subcatsub (sort @{$subcategories{$subcat}}) {
#I think this is where I should try hacking the code
$subnumlinks = ###this is the bit I cannot work out ####

#end of my hacking

$suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
if ($subcatsub =~ m,.*/([^/]+)$,) { $subcategory_name = &build_clean($1); }
else { $subcategory_name = &build_clean($subcatsub); }

$sub_length .= qq|, | if ($description =~ /1$/ && $v ne "0");
$sub_length .= qq|$subcategory_name| if ($description =~ /1$/);

if ($description =~ /1$/ && length($sub_length) > $subcat_length) {
$output .= qq|...|;
last;
}
else {
$output .= qq|, | if ($description =~ /1$/ && $v ne "0");
$output .= qq|
| if ($description =~ /2$/ || $v eq "0");
$output .= qq| | if ($description =~ /2$/);
$output .= qq|<a href="$suburl">$subcategory_name</a> ($numlinks)|;
$v++;
}
}
$output .= qq|</font>|;
}
else {
$output .= qq|
<font face="verdana" size=2>$description</font>| if (!($description =~ /^[\s\n]*$/));
}
$output .= qq|</dl>|;
}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
}

1;

any help pointers anything appreciated, spent at least 4 - 5 hours already, my project time is running out

many many thaks to anybody who can point me in the right direction, or should I be looking in the nph-build.cgi category or stats subs

Thanks

DavyC

Quote Reply
Re: SubCat Mod Number of Links in subcats In reply to
'many many thaks to anybody who can point me in the right direction, or should I be looking in the nph-build.cgi category or stats subs'

You will need to edit build single categroy sub in nph-build.cgi as well as site_html_templates.pl

Good Luck!

Glenn
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: SubCat Mod Number of Links in subcats In reply to
Hi

Worked it out

Very simple in the end

Thanks

DavyC

Quote Reply
Re: SubCat Mod Number of Links in subcats In reply to
so how did you solve it?

Any help would be appreciated.




Gene
Quote Reply
Re: [esm] SubCat Mod Number of Links in subcats In reply to
was there ever an answer to this one? i'd really like to know how to list the number of links within each subcategory.

many thanks!
Quote Reply
Re: [13thhour] SubCat Mod Number of Links in subcats In reply to
anyone have the answer to this one?
Quote Reply
Re: [Hamsterpants] SubCat Mod Number of Links in subcats In reply to
well, I can get you started but since my knowledge of perl is very limited I may not be able to help after a certain point.

Change your variable declaration at the top to include $subcatlinks.

Code:
my ($url, $numlinks, $mod, $subcat, $mycat, $category_name, $description, $output, $i, $subcatlinks);



after
$numlinks = $stats{"$subcat"}[0];
add
$subcatlinks = $substats{"$subcat"};
Now you are going to have to figure out the rest

somewhere after
foreach (sort @{$subcategories{$subcat}}) {
and before
$suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
add
$subcatlinks = $substats{$_};

Then you will see something like ( yours may read $suburl instead of $url )
$output .= qq~<a href="$url">$category_name~;

Now add the following:
if ($subcatlinks){
$output .= qq~&nbsp;($subcatlinks)~;
}
$output .= qq~</a>~;
It worked out for me to include the subcatlinks number as part of the A HREF. If that is not what you want, move the $output .= qq~</a>~; above the IF statement.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] SubCat Mod Number of Links in subcats In reply to
Hi Gene,

Thanks for the reply...my perl isn't that good either, but what it looks like you have shown me how to do is to sho the subcats.....I have that working allready. What I am trying to do is show how many links are in that subcat on the main page e.g.

Category (2)
Subcat ONE (1)
Subcat TWO (1)


The bit I am trying to do is in red.

Thanks in advance
Dill
Quote Reply
Re: [Hamsterpants] SubCat Mod Number of Links in subcats In reply to
I beleive that is what the code does.

in your example $numlinks =2 and $subcatlinks = 1

notice the foreach $subcat (sort @subcat) { in one of the earlier posts. that is the loop that prints the category. Specifically, it prints at

Code:
$output .= qq|<dl><dt><font face="verdana" size=2><a href="$url">$category_name</a></strong>
$icao <small class="numlinks">($numlinks)</small> |;


where it also prints the number of links in the category ( $numlinks )

After it prints the new icons, it starts another for loop where it looks like it prints the subcategories

Code:
foreach $subcatsub (sort @{$subcategories{$subcat}}) {


Here is where it prints the subcategory name

Code:
$output .= qq|<a href="$suburl">$subcategory_name</a> ($numlinks)|;

But I don't understand the ($numlinks) in the above. $numlinks was used to print the number of links in the category and has not been changed or reset to 0. I'm thinking it should have been $subnumlinks.

Here is my code. The only thing that seems really different is the additional for loop on the subcats.

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 (@subcat) = @_;
my ($url, $numlinks, $mod, $subcat, $mycat, $category_name, $description, $output, $i, $subcatlinks);
my ($half) = int (($#subcat+2) / 2);

$output = qq|<TABLE BGCOLOR="blue" WIDTH="420" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR><TD WIDTH="50%" VALIGN="TOP">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="5"><TR><TD VALIGN="TOP">\n|;

# Sort by Category Mod 11-20-2000. Gene.
# Comment out the following line and add the two lines after and before ($desc...
#foreach $subcat (sort @subcat) {

sub byfield { $category{$a}[$cat_sort_field] cmp $category{$b}[$cat_sort_field] };

# new images mod Mod 11-20-2000. Gene.
# foreach $subcat (sort byfield @subcat) {
# ($description) = @{$category{$subcat}}[2];
foreach $subcat (sort byfield @subcat) {
my $mod = $stats{"$subcat"}[3];
my $new_add = $stats{"$subcat"}[4];
($description) = @{$category{$subcat}}[2];

#new images Mod 11-20-2000. Gene.

# yahoo Mod 11-20-2000. Gene.
($subcatstyle) = @{$category{$subcat}}[9];

# First let's get the name, number of links, and last modified date...
$url = "$build_root_url/" . &urlencode($subcat) . "/";
if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); }
else { $category_name = &build_clean($subcat);}
$numlinks = $stats{"$subcat"}[0];
$subcatlinks = $substats{"$subcat"};
# new images Mod 11-20-2000. Gene.
# $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></TR></TABLE></TD><TD WIDTH="50%" VALIGN="TOP">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="5">
<TR><TD VALIGN="TOP">\n|;
}
$i++;

# yahoo Mod 11-20-2000. Gene.
# Then we print out the name linked, new if it's new, and popular if its popular.
# my mod to carry forward the cat name
$mycat = $category_name;
$output .= qq|<a class="menulink2" class=&{ns4class} href="$url"
onmouseover="window.status=' Check out the Listings in $category_name'; return true"
onmouseout="window.status=' '">$category_name|;
# mod to not print 0 links 1-14-2001. Gene.
if ($numlinks > 0) {
$output .= qq| ($numlinks)|;
}
$output .= qq|</a>|;


#new images Mod 11-20-2000. Gene.
# $output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);

# if ($new_add eq "Yes") {
# $days_old = &days_old($stats{"$subcat"}[2]);
# if ($days_old <= 9) { $output .= qq| $new_1|; }
# elsif ($days_old <= 19) { $output .= qq| $new_3|; }
# elsif ($days_old <= 30) { $output .= qq| $new_7|; }
# }
# if ($mod eq "Yes") { $output .= qq~ $updated~;}
#new images Mod 11-20-2000. Gene.
# $output .= qq|<BR>|;

# mod for no links in cat end

if ($subcatstyle =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($subcatstyle, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $subcatstyle);
$output .= qq~~ if ($style eq "1");
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($subcatstyle eq "ALL" && $#subcatsub == 0) ?
($_ =~ m,.*/([^/]+)$, and $category_name = &build_clean($1)) :
($_ eq "$subcat/$category_name" or next);
if ($style eq "1") {
$length += length($category_name);
($length > $subcat_length) and last;
}
#calc number of links in subcats
$subcatlinks = $substats{$_};
if ($s > 0) {
$output .= qq~~ and $length += 2 if ($style eq "1");
$output .= qq~~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~ ~ if ($style eq "2");
$output .= qq~<a class="menulink2" class=&{ns4class} href="$url"
onmouseover="window.status=' Check out the Listings in $category_name, $mycat'; return true;"
onmouseout="window.status=' '; return true;">&nbsp;&nbsp;&nbsp;&nbsp;$category_name~;
if ($subcatlinks){
$output .= qq~&nbsp;($subcatlinks)~;
}
$output .= qq~</a>~;

$s++;
last if ($subcatstyle ne "ALL" && $#subcatsub > 0);
}
}
undef $length;
if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~...~ if ($style eq "1");
}
$output .= qq~~;
$output .= qq||;
}
else { }
}

# Don't forget to end the unordered list..
# $output .= "</td></tr></table>\n";

$output .= "</TD></TR></TABLE><BR></TD></TR></TABLE>\n";
return $output;

}


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