Gossamer Forum
Home : Products : Links 2.0 : Customization :

Display total links nr. in site_html_templates.pl?

Quote Reply
Display total links nr. in site_html_templates.pl?
I would like to display total links number of the subdir, where the links was posted.
The reason why it seems difficult, it's because I want it to be displayed by the sub site_html_add_success. So it should be displayed after the form was posted successfully.
Link counting is done in nph_build.cgi, so I had to implement the link counting routine into site_html_templates.pl:
Code:
sub category_link_count {
# --------------------------------------------------------
# It finds out how many links are in each category

my $category = $_;
my (@values, $cat, @alt_categories, @categorylist, $depth, $i, $cat);

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 ($_);

# Add the link to the list of links.
push (@{$links{$category}}, @values);
$grand_total++;

# Calculate the stats: the number of links and the newest link.
@categorylist = split (/\//, $category);
$depth = $#categorylist;
}
close DB;
return $depth;
}
I call this sub in site_html_add_success like this:
Code:
$total = &category_link_count ($category);
Then associate the name:
Code:
total => $total,
I don't know why, but it's not working fine. I get -1 as total link number.
What can be the problem?

Thanks,
Webmaster33


[This message has been edited by webmaster33 (edited March 05, 2000).]
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
Just bringing this topic to the top. I hope somebody can help me.
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
The problem I see with your codes is that you are using the $category variable, when you should be using $subcat to extract the number in that subcategory, not just the category, which is your goal, right?

Also, you have no counting mechanism in your codes, like the following:

Code:
my $count = 0;

and then a final count:

Code:
++$count;

Yes...you have ++grand_total;

If you want to use this in your codes, then you need to add the following at the top of your codes after the my $category = $_;:

Code:
my $grand_total = 0;

And you should return the $grand_total, NOT the depth variable.

like the following:

Code:
return $grand_total;

And to call this sub for the variable to create a tag in the sub html_add_success, all you have to do is add the following codes:

Code:
catcount => &category_link_count,

Hope this helps.

Regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
  
Quote:
you should be using $subcat to extract the number in that subcategory, not just the category
Well, here's an example.
If the user posted the link into /Computers/Printers/Accessories, on the add_success.html should display the number of all links in this category (only this category, because I allow to post only into the last category in the deep of the tree): e.g. Accessories (16)

I hope it's clear now, what I want.

Today I will try your suggestion.
If you have suggestions, after reading the example above, let me know.

Regards,
Webmaster33


[This message has been edited by webmaster33 (edited March 07, 2000).]
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
I do understand what you are after. And it makes better sense now, however, what threw me off in your initial posting, was that you want the number of links in the subcategory.

Do you even see the problem I have pointed out in terms of the counting problem? Or did you choose to ignore that part? *sigh*

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
  
Code:
# Calculate the stats: the number of links and the newest link.
@categorylist = split (/\//,$category);
$depth = $#categorylist;
Note, that the sub category_link_count is processed only once per subcategory. The $#categorylist gives a number in result, which is the number of the elements in this array, so it's the number of the links in this subcat.
That's why the ++$count; would not work to count links in this subdir.

Right?
I interpreted this code for myself as I explained above.
Otherwise, the $grand_total is unnecessary for the effect I want (link counting in the subdir where the link was submitted & display of it in the add_success.html).

What do you think?

Webmaster33

[This message has been edited by webmaster33 (edited March 07, 2000).]
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
I don't agree...I think that you need to have a count variable that starts with 0 and then increments after pulling data from the particular sub you are looking at, which in this case is the &category_list.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
Ok. I will try your suggestion. I'm not sure it will do the desired effect, but I hope it will work.

I will let you know the result later.

Regards,
Webmaster33
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
You are right, Eliot! Your suggestion worked!
Here's the full solution if anybody need it:
site_html_templates.pl:
Code:
sub category_link_count {
# --------------------------------------------------------
# It finds out how many links are in current category
my $this_cat = @_[0];
my (@values, $category, $subtotal);

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;
}
The rest is the same as in my original post.

I hope it will be useful for others, too.

Regards,
Webmaster33
Quote Reply
Re: Display total links nr. in site_html_templates.pl? In reply to
Good....

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: [webmaster33] Display total links nr. in site_html_templates.pl? In reply to
How would I make this work like this:

$subcatnamecount = category_link_count("Subcatname")

and then:

subcategorynamecount => $subcatnamecount

in the sub site_html_home to make a tag <%subcatnamecount%> for different category names to insert in my home.html template?

I am looking to be able to insert something like "The category subcategoryname has <%subcatnamecount%> links in it." in my home page without calling the <%category%> variable. I have a static home page with static graphics and links to the top categories, and all I need to be updated at build time is the numlinks of the 3 toplevel categories and not all the other html created by the <%category%> tag.

Hope this makes sense.

Charlie