I hope someone can help me with this... I am trying to create a tag in the home.html to show the number of links in the top categories. I think the problem is in how I am trying to pass the category name to the subroutine, but I am not a programmer so I am not sure. (I am trying to learn however.) What I am wanting to do is simply place a line like "There are XXX links in the Topcategoryname1 category." for selected categories. I am not getting any errors, I'm not even getting Unknown Tag: <%cat1count%>, so I must be somewhat close. If someone could take a look and advise, I would appreciate it greatly. I got the code from another thread in this forum, it is not mine.
Charlie
I am calling the tags in home.html with <%cat1count%>, <%cat2count%>, <%cat3count%>.
Below is what I added (changed) in the sub in site_html_templates.pl:
sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.
### Added lines
$cat1count => &category_link_count ('Topcategoryname1');
$cat2count => &category_link_count ('Topcategoryname2');
$cat3count => &category_link_count ('Topcategoryname3');
### Added lines
return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
### Added lines
cat1count => $cat1count,
cat2count => $cat2count,
cat3count => $cat3count,
### Added lines
%globals
});
}
Below is the subroutine I added and tried to adapt from another thread at the bottom of site_html_templates.pl:
### Added subroutine
sub category_link_count {
# --------------------------------------------------------
# It finds out how many links are in current category
my $this_cat = @_[0];
my (@values, $category, $subtotal);
my $subtotal = 0;
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];
if ($this_cat eq $category) {
$subtotal++;
}
}
close DB;
return $subtotal;
}
### Added subroutine
Charlie
I am calling the tags in home.html with <%cat1count%>, <%cat2count%>, <%cat3count%>.
Below is what I added (changed) in the sub in site_html_templates.pl:
sub site_html_home {
# --------------------------------------------------------
# This routine will build a home page. It is not meant to have any
# links on it, only subcategories.
### Added lines
$cat1count => &category_link_count ('Topcategoryname1');
$cat2count => &category_link_count ('Topcategoryname2');
$cat3count => &category_link_count ('Topcategoryname3');
### Added lines
return &load_template ('home.html', {
category => $category,
grand_total => $grand_total,
### Added lines
cat1count => $cat1count,
cat2count => $cat2count,
cat3count => $cat3count,
### Added lines
%globals
});
}
Below is the subroutine I added and tried to adapt from another thread at the bottom of site_html_templates.pl:
### Added subroutine
sub category_link_count {
# --------------------------------------------------------
# It finds out how many links are in current category
my $this_cat = @_[0];
my (@values, $category, $subtotal);
my $subtotal = 0;
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];
if ($this_cat eq $category) {
$subtotal++;
}
}
close DB;
return $subtotal;
}
### Added subroutine