Gossamer Forum
Home : Products : Links 2.0 : Customization :

Can someone see what's wrong with this code?

Quote Reply
Can someone see what's wrong with this code?
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

Quote Reply
Re: [cvance] Can someone see what's wrong with this code? In reply to
I stand corrected... I AM getting Unknown Tag errors in the home page.

Help, please.
Quote Reply
Re: [cvance] Can someone see what's wrong with this code? In reply to
What I would recommend doing is the following (much simpler than what you are attempting to do):

1) Add a column/field in the category.def file called something like "SelectCategory". You'll need to update your categories.db file by adding a delimiter at the end of each record.

More info: Search the Links 2.0 forums for adding fields categories.

2) Then in your sub site_html_print_cat, add a conditional (if) statement that references that new field.

Something like the following:

if ($selectcategory) {
$output .= "This category has $numlinks";
}

You'll need to define the $selectcategory var at the top of the sub.

Good luck!
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Can someone see what's wrong with this code? In reply to
I see how that would work on the category pages, but would it work as a <%tag%> on my home.html template? My home page (top level categories) is a static page with all the graphics, and links, etc, and the only thing that I need to be updated when I do the nph-build is the link counts for each of the 3 toplevel categories. (I hope I don't sound ignorant... If you want to see what I mean, go to http://www.sexywebpass.com/links.html and you'll see what I am trying to do.)

Charlie
Quote Reply
Re: [cvance] Can someone see what's wrong with this code? In reply to
Uh...buddy...that SUB is what PRINTS category layouts in the HOME PAGE and CATEGORY pages! It prints out the <%category%> tag, WHICH is in the HOME PAGE. Please try to learn more about the logic of the program before questioning advice provided.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Stealth] Can someone see what's wrong with this code? In reply to
I'll give it a try. I didn't mean to sound like I was questioning your advice, I was just asking a question because I wasn't sure I was being clear on what I was trying to do, and I definitely didn't mean to sound ungrateful.

I'll give it a try, and again, I appreciate the help.

Charlie
Quote Reply
Re: [Stealth] Can someone see what's wrong with this code? In reply to
Doesn't work for what I need it to do... I am not calling the <%category%> tag in home.html, because I don't want all the category names listed, ONLY the number of links in a category in a <%tag%>. I have 3 top level categories, each with a graphic and link, etc, on the home page. All I need is a way to create a <%tag%>, for example, <%categoryname1count%>, <%categoryname2count%>, etc for the top 3 level categories so that the number of links will be updated when the pages are rebuilt.

Doing it the way you suggested generates all the category names, descriptions, etc, which is fine for all my other category (subcategory) pages, but will mess up my home page. I hope this all makes sense, and I DO follow the logic of the system for the most part, that is why I tried to adapt this subroutine so I could get that tag without calling the <%category%> tag, I'm just not familiar enough with perl to see where I went wrong.

Thanks,
Charlie