Gossamer Forum
Home : Products : Links 2.0 : Customization :

Comments4 lite

Quote Reply
Comments4 lite
I was able to install the Comments 4 lite mod from:

http://cgi-resource.co.uk/pages/comment4l.html

However, I cannot get the total comments to show up. After the pages are built, the links page has an error: Unknown tag totals

Apparently, the <%totals%> is not being recognized. Here is what my sub site_html_link in site_html_templates.pl looks like...

Code:

sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.
my %rec = @_;
# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});
return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
# Added for comments4
my (@values, $counter, $totals);
$counter = 0;
open (DB, "<$db_comments_name") or &cgierr("unable to open database: $db_comment_name. Reason: $!");
LINE: while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp;
@values = &split_decode ($_);
$counter = $values[1];
if ($rec{'ID'} eq $counter) {
$totals++;
}
}
close DB;
totals => $totals,
}


Do you spot something wrong?

Thanks in advance!!
Quote Reply
Re: [aznaphrodite] Comments4 lite In reply to
I did not look over the insrtructions just now, not sure how they read, but what I see is that the part you added is not "connected" to anything. Add this to link.html:

Code:

sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.
my %rec = @_;
# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});
return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",

totals => &comments_total($rec{'ID'}),
%rec,
%globals
});

}


Then make the other code a subroutine. You can add it just under the above routine.

Code:


# Comments 4 mod >
sub comments_total {
#----------------------------------------
# Gets the number of comments for a link.
my (@values, $counter, $totals);
$counter = 0;
open (DB, "<$db_comments_name") or &cgierr("unable to open database: $db_comment_name. Reason: $!");
LINE: while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp;
@values = &split_decode ($_);
$counter = $values[1];
if ($rec{'ID'} eq $counter) {
$totals++;
}
}
close DB;
}
# < Comments 4 mod


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Nov 19, 2005, 9:22 PM
Quote Reply
Re: [PerlFlunkie] Comments4 lite In reply to
Thanks for the help, PerlFlunkie! I did what you said but now it's showing 1 comment for every link, even though some have no comments and some have more than 1.

http://ladyrebecca.com/bridezilla/Florists/

Any ideas?

Thanks in advance!
Quote Reply
Re: [aznaphrodite] Comments4 lite In reply to
Okay, I looked over the instructions, and they are a bit unclear, but it looks like you should do this:

Code:

sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.
my %rec = @_;

my (@values, $counter, $totals);
$counter = 0;
open (DB, "<$db_comments_name") or &cgierr("unable to open database: $db_comment_name. Reason: $!");
LINE: while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp;
@values = &split_decode ($_);
$counter = $values[1];
if ($rec{'ID'} eq $counter) {
$totals++;
}
}
close DB;
}


# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});
return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
totals => $totals,
%rec,
%globals
});

}


See if that works...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Comments4 lite In reply to
Worked like a charm!!! THANK YOU!!!!