Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Change / to > in Related Categories

Quote Reply
Change / to > in Related Categories
Hi to everyone,

In the category pages, the "Related Categories" are like this:

Computers/Hardware/Monitors

But I need to change this to:

Computers > Hardware > Monitors (23)

It was ok in Links2.0 but in Links SQL I am not able to modify the codes, that's of course because of my poor Perl knowledge. I think (hope) this is not a very hard modification, and I couldn't find anything useful in forum and also in the FAQ.

Any help will be greatly appreciated.

Thanks.

timberg

Quote Reply
Re: Change / to > in Related Categories In reply to
In both page.cgi & nph-build.cgi, go to sub generate_category_page follow it down to this bit of code:
Code:
# Calculate the related entries and put in a <LI> list.
$get_related = $LINKDB->prepare ("CUT TO FIT");
$get_related->execute($OUT{category_id});
$OUT{related} = '';
while (($name) = $get_related->fetchrow_array) {
$OUT{related} .= qq|<a href="$LINKS{build_root_url}/|;
$OUT{related} .= &build_clean_name ($name);
$OUT{related} .= qq|/$LINKS{build_index}">|;
$OUT{related} .= qq|$name</a>\n|;
}
Then add in something like the following:
Code:
# Calculate the related entries and put in a <LI> list.
$get_related = $LINKDB->prepare ("CUT TO FIT");
$get_related->execute($OUT{category_id});
$OUT{related} = '';
while (($name) = $get_related->fetchrow_array) {
$OUT{related} .= qq|<a href="$LINKS{build_root_url}/|;
$OUT{related} .= &build_clean_name ($name);
$OUT{related} .= qq|/$LINKS{build_index}">|;
my $new_name = ($name =~ s/\// \>/g);
$OUT{related} .= qq|$new_name</a>\n|;
}
Quote Reply
Re: Change / to > in Related Categories In reply to
Hi phoule,

Thanks for your help. I have modified the two files according to your instructions. But now the category names are lost, instead of them, there are unique numbers like 1, 2, 3...

I have tried many times, but the result is still same.

Here is the code in my Links SQL version 1.13:


page.cgi

# Calculate the related entries and put in a <LI> list.
$get_related = $LINKDB->prepare (" SELECT Category.Name FROM CategoryRelations, Category WHERE CategoryRelations.CategoryID = ? AND CategoryRelations.RelatedID = Category.ID");
$get_related->execute($OUT{category_id});
$OUT{related} = '';
while (($name) = $get_related->fetchrow_array) {
$OUT{related} .= qq|<li><a href="$LINKS{build_root_url}/|;
$OUT{related} .= &build_clean_name ($name);
$OUT{related} .= qq|/$LINKS{build_index}">|;
my $new_name = ($name =~ s/\// \>/g);
$OUT{related} .= qq|$new_name</a></li>|;
}


nph-build.cgi

# Calculate the related entries and put in a <LI> list.
$get_related->execute($OUT{category_id});
$OUT{related} = '';
while (($name) = $get_related->fetchrow_array) {
$OUT{related} .= qq|<li><a href="$LINKS{build_root_url}/|;
$OUT{related} .= &build_clean_name ($name);
$OUT{related} .= qq|/$LINKS{build_index}">|;
my $new_name = ($name =~ s/\// \>/g);
$OUT{related} .= qq|$new_name</a></li>|;
}

I hope this code may be a reference for the problem. Why do you think that the result only gives numbers instead of category names (These numbers are not category ID's they're unique numbers like 1, 2, etc.)?

Thank you again for your reply.

Quote Reply
Re: Change / to > in Related Categories In reply to
Hmmm...I'm not really sure. Maybe by changing the value of $name in the loop something is occuring to throw off the loop conditions, though that doesn't seem right, it could happen. Play with a bit and use print statements to see what the values are for $new_name & $name both before and during the loop. It may give you some hints. Also try:
my $new_name = $name;
$new_name =~ s/\// \>/g;

Instead of:
my $new_name = ($name =~ s/\// \>/g);

I was just trying to save a line and do 2 things at once but's not really necessary.

Quote Reply
Re: Change / to > in Related Categories In reply to
Timberg,

Try this:

$OUT{related} .= qq|<li><a href="$LINKS{build_root_url}/|;
$OUT{related} .= &build_clean_name ($name);
$OUT{related} .= qq|/">|;
$OUT{related} .= &build_unlinked_title ($name);
$OUT{related} .= qq|</a></li>|;

I haven't tested it but it's only the $name part of the link that you need to change and this sub already exists in DB_Utils.pm.

Let me know how it works out Smile

All the best
Shaun
Quote Reply
Re: Change / to > in Related Categories In reply to
Thanks phoule and qango,

Now it works by the final suggestion of phoule and also by the suggestion of qango. All "/" can be changed to ">" or whatever you want.

However, the number of links in the categories are not shown yet. I have tried to use templates and put <%Number_of_Links%> tag, but it doesn't work of course. Crazy

I would like to ask about this now, is there any way to show the number of links near the related categories list in the category pages?

I will be very pleased if you can also help about this question.

Thank you again guys for your help.


Quote Reply
Re: Change / to > in Related Categories In reply to
As far as I'm aware, the number of links are only calculated for each 'Category' and not for 'Related' categories.

All the best
Shaun