Gossamer Forum
Home : Products : Links 2.0 : Customization :

Category Referring to another - Simular to Yahoo

Quote Reply
Category Referring to another - Simular to Yahoo
I'm not sure if this is of interest to anyone, or if it's been done before, but I've made a mod to do it. After I started this I found that Yahoo had a simular feature, so I made it look the same as theirs.

Let me show you an example to help explain:

Games/Internet
Internet/Games

Both categories would have simular links. I wanted all the links to be in the one place so visitors didn't have to hunt so hard. I devised a way to allow one of the categories to just refer the visitor to the other(in this case Games/Internet would hold the links). I then set it up so refering categories are no longer built. Then, using Bobsies's select list mod(with a small modification) I prevent people from adding links to the referring category. To see an example of this feel free to go to my site. http://gottabounce.hypermart.net/ and look under the categories Internet, and Recreation to see examples. If anyone is interested, I'll be glad to write up how I did it and post it here.

Sheldon
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Nice job! It seems to conserve disk space as well as make it easier for users to find information.

I would recommend posting instructions. My site is constructed like yours. It would be nice to find a way to conserve disk space and enhance navigation. This mod seems to accomplish this.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
For the purposes of this mod I used the @ symbol as the key. You can probably use any symbol, but you want to choose one that you will not use in category names for anything other than this mod.

To start with if you don't already have Bobsie's Select Category list mod installed ( goodstuff.orphanage.com/rcat_mod.html ) You will want to install it.

Once you've installed that you'll want to make a Modification to his site_html_cat_select_list(The change in the code is Bolded):
Code:
sub site_html_cat_select_list {
# --------------------------------------------------------
# This routine builds the options for the category select list.
my (@subcat) = @_;
my $output;

CAT: foreach $subcat (sort @subcat) {
if (@exclude_categories) {
foreach (@exclude_categories) {
($subcat eq $_ | | $subcat =~ /\@$/) and next CAT; #Prevents visitors from adding to categories with the @ symbol
}
}
$category_name = &build_clean($subcat);
$output .= qq| <option value="$subcat">$category_name\n|;
}
return $output;
}
NOTE: in the changed line there are two pipes ( | | ) there should be no space inbetween them

The change here prevents visitors from adding to categories that contain the @ symbol.

Next open the nph-build.cgi and find the sub build_category_pages {. Add the Bolded line into the code
Code:
# Go through each category and build the appropriate page.
CATEGORY: foreach $cat (sort keys %category) {
next CATEGORY if ($cat =~ /^\s*$/); # How'd that get in here? =)
next CATEGORY if ($cat =~ "@"); #Prevents Categories with the @ symbol from being Built
next CATEGORY if ($build_single and ($build_single ne $cat));
This change skips the categories with the @ symbol in the category page building process.

To display the new category format and link it to the desired category open your site_html_templates.pl(if you don't use templates this should work in the site_html.pl too, but I have not done it). In the sub site_html_print_cat { Replace this...
Code:
# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
With this...
Code:
# Then we print out the name linked, new if it's new, and popular if its popular.
if ($category_name=~ "@") {
$output .= qq|<dl><dt><strong><a class="link" href="$build_root_url/$description/">$category_name</a></strong> |;
}
else {
$output .= qq|<dl><dt><strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;
}

Now to edit the desired category you want to work with this mod. Say you want the Category Internet/Games to refer visitors to Games/Internet. In the admin Add/modify a category window change the name of the Category Internet/Games by adding the @ sign to the end of it...

Internet/Games@

Then in the Description type the name of the Category you are referring it to..

Games/Internet

Note: Don't add begining or trailing slashes.

This next part is only for people who have installed Widgetz's Subcategories like Yahoo mod(I don't know the URL, but I think it's in the Resource Center). As I found out, sometimes one of the modified categories will show up in the subcategories display. Even though the modified category is set up right, when displayed under it's main category it wants to link as if it were normal. I had two choices...

1. Use a If/else statment in widgets mod like the one used above in the sub site_html_print_cat to get it to link right, or
2. Don't let the modified categories to be displayed at all in this mod.

I choose to do the second option. In Widgetz's mod he places the following bit of code in the sub site_html_print_cat. Add the Bolded line into that code.

Code:
if ($#{$subcategories{$subcat}} >= 0 && $description =~ /^SUB.*/) {
$v = 0;
$sub_length = "";
$output .= qq| |;
foreach $subcatsub (sort @{$subcategories{$subcat}}) {
next if ($subcatsub=~ "@");
$suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
if ($subcatsub =~ m,.*/([^/]+)$,) { $subcategory_name = &build_clean($1); }
else { $subcategory_name = &build_clean($subcatsub); }

$sub_length .= qq|, | if ($description =~ /1$/ && $v ne "0");
$sub_length .= qq|$subcategory_name| if ($description =~ /1$/);

if ($description =~ /1$/ && length($sub_length) > $subcat_length) {
$output .= qq|...|;
last;
}
else {
$output .= qq|, | if ($description =~ /1$/ && $v ne "0");
$output .= qq| | if ($description =~ /2$/ | | $v eq "0");
$output .= qq| | if ($description =~ /2$/);
$output .= qq|<a href="$suburl">$subcategory_name</a>|;
$v++;
}
}
$output .= qq| |;
}
else {
$output .= qq|$description| if (!($description =~ /^[\s\n]*$/));
}


This is my first attempt at making and posting a mod I hope I explained it well and didn't leave anything out. If you install this please let me know how it works, especially if there are any problems.

Sheldon

[This message has been edited by PlanetSheldon (edited July 31, 1999).]

[This message has been edited by PlanetSheldon (edited July 31, 1999).]
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
i think you should change all the

blah blah =~ "@" to:

blah blah =~ /\@$/

it might not need the \ in front of it.. that checks for it to be at the end only..

jerry
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Thanks for the help Jerry,

I'm still really new to programing CGI's. 2 months ago I didn't even know what a CGI was let alone open one up to make changes to it.

Sheldon
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Sheldon,

Nice script. Tell me though (I am curious), how does this differ from using the related category feature of Links?
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
In ways it's very simular, but in other ways it's different. Like the related categories, it indicates different category that goes along with that particular topic. But as for my site categories like my example:

Games/Internet
and
Internet/Games

are both equally important and I wanted all the links bunched in one place to make finding things easier for visitors. What I was actually thinking of when I made this was I wanted all the links for each of those two categories to be placed in one collective pool. That way it wouldn't matter if you clicked on Games/Internet, or Internet/Games, you'd see the same list. It didn't take me long to scrap that idea realizing that it would take up twice as much disk space. I came up with this instead where Games/Internet is like the "pool" and Internet/Games "pulls" the same list.

Another thing is this put is right in the middle of the Category list rather than at the bottom, were it can get over looked.

If nothing else it's another way to do the related categories.

Sheldon
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
I understand now. Thanks. I might give that a try when I (if I) get time.

Also, you do realize, don't you, that the Related Categories can be placed anywhere on the Category pages? Nothing says they "have" to be at the bottom. They could be at the top, on the left, right, or smack dab in the middle (that would look good, eh?).
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Yup, your right, that would be fine.

Sheldon
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Cool. Thanks PS. I'll have to go back and pick up Bobsies select cat mod first...I never had to ban a category so I didn't worry about it.
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Forgive for asking a stupid question...in essence the @ category is a link to another category, yes? Does this mean I can have several @ categories refer to the same main or subcategory?
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Ok, I got it working. Two notes for anyone else who wants to do this:

You must first install the mod to allow the @ character in the category name (or you will get an error). Instructions are at:
www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/001722.html

To prevent the category description from printing under @ categories, in site_html_templates.pl, sub site_html_print_cat, I changed:

Code:
$output .= qq|<dd><font face="arial, helvetica, sans-serif" size="2"><span class="descript">$description</span></font></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;

TO:
Code:
if ($category_name=~ "@") {
$output .= qq|</dl>|;
}
else {
$output .= qq|<dd><font face="arial, helvetica, sans-serif" size="2"><span class="descript">$description</span></font></dd>| if (!($description =~ /^[\s\n]*$/));
$output .= qq|</dl>|;
}
Note that this change includes my font and other formatting stuff...just make it match what you have in yours. Also, I do not use widgetz yahoo like subcat mod and have no idea if you need to do this if you are.

One of the perl folks around here may have a suggestion to make this simplier--but it works for me!
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Sorry About that Brad, I knew I was forgetting soemthing but I could remember what...other than that you got it workign ok?

I don't know if you want to, but I went and followed widgetz advice on making it so it only looks for the @ sign at the end of the category name.

Keep me informed, thanks
Sheldon
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
I just noticed that after adding the mods to do this, my add form doesn't automatically populate the category name when add is clicked from a "valid" category. Since I added the mods one on top of the other, I don't know if Bobsie's mod changed this behavior, or if PS's change to that mod would do it. Of course, maybe I just jacked something up all on my own! Ideas?
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
Brad,
What do you mean by populate? Like it's not building the category select list? I don't seem to be having a problem, but that doesn't mean anything...For a point of referance, incase it's a problem with the change I made to bobsie's mod, Widgetz helped me out with the code at this thread
http://www.gossamer-threads.com/...um3/HTML/002339.html

Keep me posted,
Sheldon

------------------
webmaster@gottabounce.com
www.gottabounce.com

Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
What I mean by populate is the category name was filled in automatically when you would add a site from within the category (drop down list from home and other non category pages). Now, I'm always getting the drop down list even when I select "add" from a category page. I didn't alter the setting in links.cfg, so I'm thinking it must be something about the mod.

Is anyone out there only using Bobsie's exclude mod and having this problem?
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
hey planet.. if you want the description and the correct url..

look at

http://www.gossamer-threads.com/...um3/HTML/003110.html

tommorrow i am going to complete this mod.. it's simple.. the beginning is basically yours.. excpet i plan on using the description field to tell links where to send the user..

jerry
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
hi,
Thank you for this mod . just installed it , and i have one problem ;

i get the name of the category im referring to, on top of the list of the subcategories .
example :

in the category : Amr_Diab
i want : Shop@
to refer to : CD_Shop/Amr_Diab

so, in: Amr_diab/

i get the subcategpries, with : CD_Shop/Amr_Diab ( in plain text ) on top of the subcategories.

can someone help please,
Thnak you,

Laith
Quote Reply
Re: Category Referring to another - Simular to Yahoo In reply to
which mod did you install mine or his?

try mine.. it's easier. and probably less buggy.. (it's in the message i posted up)

jerry