Gossamer Forum
Home : Products : Links 2.0 : Customization :

Sub-Categories for Links

(Page 1 of 2)
> >
Quote Reply
Sub-Categories for Links
 
How do I get subcategories to appear on the main page? Just like Yahoo... Links only displays the main category by default. I know there is a way to mess with the code and get this done but I know little about coding.... Is there a place where I could copy the script or modification for this? Thank you.
Quote Reply
Re: Sub-Categories for Links In reply to
RP,

Please try searching for answers using the Search feature before asking questions. You'll find this has been answered many times.

Take a look at this: http://www.gossamer-threads.com/...um3/HTML/000793.html

Phoenix
Quote Reply
Re: Sub-Categories for Links In reply to
 
Sorry about that.... I'm a bit raw with this whole bulletin board thing... Thanks though... at least I found my answer.
Quote Reply
Re: Sub-Categories for Links In reply to
Hi...

If you want to build subcategories under the categories automatically, I made a MOD that you can use. Just follow these instructions, they are easy!

In sub site_html_print_cat find the line:

Code:
$output .= qq~<dd><span class="descript">$description</span></dd>~ if (!($description =~ /^[\s\n]*$/));

and replace it with:

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

$output .= qq~<br>~ if ($description =~ /2$/ | | $v eq "0"); # CHANGE "| |" (NO SPACE)!!!
$output .= qq~&[nbsp];&[nbsp];~ if ($description =~ /2$/); # REMOVE "["s and "]" FROM THIS LINE!!!
$output .= qq~<a href="$suburl">$subcategory_name</a>~;
$output .= qq~, ~ if ($description =~ /1$/ && $v ne $#{$subcategories{$subcat}});
$v++;
}
$output .= qq~</font>~;
}
else {
$output .= qq~<dd><span class="descript">$description</span></dd>~ if (!($description =~ /^[\s\n]*$/));
}

!!! You will need to change the line with "| |" in it cause this message board splits them up. They should be stuck together (no space in between them)

AND

ON THE LINE WITH &[nbsp];&[nbsp]; change it so it doesn't have the "["s or the "]"s. The message board took them out. !!!


There are 2 styles that this will make.

If you want the style that looks like this:

Category
Subcategory1, Subcategory2, Subcategory3

Go to the category, you want to use, and edit it's description to: SUB1

OR

If you want the style that looks like this:

Category
Subcategory1
Subcategory2
Subcategory3

Go to the category, you want to use, and edit it's description to: SUB2

Then build the pages!

It lists all the subcategories, so you may not like it but I made it the way I wanted it, so I don't plan on changing it to limit only a certain number of letters or something.

Also, if you use the second style, it wouldn't look good if you had ALOT of subcategories in one category and not in another, cause one end will be longer than the other.

HOPE THAT HELPS!
Jerry

[This message has been edited by widgetz (edited June 23, 1999).]

[This message has been edited by widgetz (edited June 23, 1999).]
Quote Reply
Re: Sub-Categories for Links In reply to
Hey, Nice job on that mod!
I know there has been many people looking for something like this. I set it up and it worked great. I do have a question, as I am not 100% comfortable with coding cgi. I am using your mod in sub site_html_print_cat, and was wondering how hard it would be to put the categories in a form list. Like this:

<FORM name = "form">
<SELECT NAME="site" SIZE=1 onChange ="formHandler(this.form)">
<OPTION VALUE="">--Select a Subcategory--
<OPTION VALUE="/links/subcat1/">subcat1
<OPTION VALUE="/links/subcat2/">subcat2
<OPTION VALUE="/links/subcat3/">subcat3
</SELECT></FORM>

Maybe this could be SUB3.

This would make my life immeasurably easier.
Thanks again for the nice mod.
Aaron

------------------
www.serve.com/garden/geosearcher





[This message has been edited by Aaron (edited June 23, 1999).]
Quote Reply
Re: Sub-Categories for Links In reply to
well, you put SUB in the description of the category that you want to show up with the sub categories...

FIRST.. try it on your "root" category... the most popular seems to be "Computers", so let's say "Computers".. go to the administration place and modify the category "Computers".. edit it's description to say:

SUB

then build the pages.. if it still just writes "SUB" it's probably cause that category has no sub categories in it...

Hope that helps
Jerry
Quote Reply
Re: Sub-Categories for Links In reply to
look up at my post.. i changed the coding.. i changed a number and i changed the yahoo style to type in: SUB1 so that SUB thing wouldn't happen
Quote Reply
Re: Sub-Categories for Links In reply to
I went ahead and implemented what aaron wanted... the thing is that you will need to supply your own javascript / form for it... if you don't want the javascript thingy.. use the original one i posted on top....

1. Find in site_html.pl in the subcategory site_html_print_cat:

Code:
$output = qq~<div class="margin"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n~;

REPLACE WITH:

$output = qq~<div class="margin"><form name = "##CHANGE##"><table width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td class="catlist" valign="top">\n~;

2. Find in site_html.pl in the subcategory site_html_print_cat:

Code:
$output .= qq~<dd><span class="descript">$description</span></dd>~ if (!($description =~ /^[\s\n]*$/));

REPLACE WITH:

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

$output .= qq~<br>~ if ($description =~ /2$/ | | $v eq "0"); #DELETE SPACE BETWEEN "| |"!!!
$output .= qq~&[nbsp];&[nbsp];~ if ($description =~ /2$/); #DELETE "["s and "]"s!!!
$output .= qq~<select><option value="">--Select a Subcategory--~ if ($description =~ /3$/ && $v eq "0");
$output .= qq~<a href="$suburl">$subcategory_name</a>~ if ($description =~ /1$/ | | $description =~ /2$/); #DELETE SPACE BETWEEN "| |"!!!
$output .= qq~<option value="$suburl">$subcategory_name~ if ($description =~ /3$/);
$output .= qq~, ~ if ($description =~ /1$/ && $v ne $#{$subcategories{$subcat}});
$output .= qq~</select>~ if ($description =~ /3$/ && $v eq $#{$subcategories{$subcat}});
$v++;
}
$output .= qq~</font>~;
}
else {
$output .= qq~<dd><span class="descript">$description</span></dd>~ if (!($description =~ /^[\s\n]*$/));
}

3. Find in site_html.pl in the subcategory site_html_print_cat:

Code:
$output .= "</td></tr></table></div>\n";

REPLACE WITH:

$output .= "</td></tr></table></form></div>\n";

!!! YOU HAVE TO CHANGE 4 THINGS BY YOURSELF (the message board screwed them up or i couldn't do it..)

1. Change the form to point to a cgi, make the neccesary changes so that the script will work without a submit buttom...

2. Find: $output .= qq~<br>~ if ($description =~ /2$/ | | $v eq "0");

EDIT: "| |" shouldn't have a space in the middle. Delete the space.

3. The line below that, has 2 "&[nbsp];"s. Delete the "["s and the "]"s.

4. Two lines below that, delete the space in between the "| |" !!!


If you want subcategories that look like this:

Category
Subcat1, Subcat2, Subcat3

Type: "SUB1" into the categories description.

If you want subcategories that look like this:

Category
Subcat1
Subcat2
Subcat3

Type: "SUB2" into the categories description.

If you want subcategories that look like this:

Category
(Pulldown List of Subcategories)

TYPE: "SUB3" into the categories description.

OK... HOPE THAT HELPS

Jerry



[This message has been edited by widgetz (edited June 23, 1999).]
Quote Reply
Re: Sub-Categories for Links In reply to
Hello

I tried your mod but all it did was to put "SUB" under my topic. Please clarify what you mean by putting SUB in the description field. Please excuse the ignorance.
Quote Reply
Re: Sub-Categories for Links In reply to
We did what you said, put the new code up, put SUB1 in the description of our main category which has six sub categories, ran the build and all it did was put SUB1 under the Main category. Everything else in the program executes flawlessly. Cannot figure this one out.
Quote Reply
Re: Sub-Categories for Links In reply to
2 questions..

are you using nt or unix?

and what is the URL?

thanks!
Quote Reply
Re: Sub-Categories for Links In reply to
another reason could be cause you use templates.. i don't use templates and i don't plan to...

Smile

jerry
Quote Reply
Re: Sub-Categories for Links In reply to
Using Unix and yes, am using templates. Guess that is why.
Quote Reply
Re: Sub-Categories for Links In reply to
How to do someting similar when using templates?
Quote Reply
Re: Sub-Categories for Links In reply to
i don't use templates.. so i have no idea how templates work.. as a matter of fact i wiped out templates completely from all of my scripts Smile

jerry
Quote Reply
Re: Sub-Categories for Links In reply to
Ok, I got the SUB3 method working, with some modifications.
I am using templates, but it shouldn't matter, both templates and non templates use site_html.pl or site_html_templates.pl.

Here is what I have:
in site_html.pl in the subcategory site_html_print_cat:

YOU ONLY NEED TO MAKE CHANGES TO THIS PART
Code:
if ($#{$subcategories{$subcat}} >= 0 && $description =~ /^SUB.*/) {
$v = 0;
# $output .= qq~<$font_small>~;
foreach $subcatsub (sort @{$subcategories{$subcat}}) {
$suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
if ($subcatsub =~ m,.*/([^/]+)$,) { $subcategory_name = &build_clean($1); } else { $subcategory_name = &build_clean($subcatsub); }
$output .= qq~~ if ($description =~ /2$/ | | $v eq "0");
$output .= qq~  ~ if ($description =~ /2$/);
$output .= qq~<FORM name = "form"><SELECT NAME="site" SIZE=1 onChange ="formHandler(this.form)"><option value="">--Select a Subcategory--~ if ($description =~ /3$/ && $v eq "0");
$output .= qq~<a href="$suburl">$subcategory_name</a>~ if ($description =~ /1$/ | | $description =~ /2$/);
$output .= qq~<option value="$suburl">$subcategory_name~ if ($description =~ /3$/);
$output .= qq~, ~ if ($description =~ /1$/ && $v ne $#{$subcategories{$subcat}});
$output .= qq~</select></form><BR>~ if ($description =~ /3$/ && $v eq $#{$subcategories{$subcat}});
$v++;
}
$output .= qq~</font>~;
}
else {
$output .= qq~<dd><font face="Times New Roman" size=1>$description</font>~ if (!($description =~ /^[\s\n]*$/));
}
Nads in my Header.txt or header section (for non-templates) I included:
Code:
<script language="JavaScript">

function formHandler(form){
var URL = form.site.options[form.site.selectedIndex].value;
window.location.href = URL;
}
</script>

I only have one possible imrovement: Is there a way to include a form even if there are no subdirectories? maybe just a form field that says "none"?
This would help immensly with formatting, and you could then use SUB3 in all of the category descriptions fields.

Aaron

------------------
www.serve.com/garden/geosearcher





[This message has been edited by Aaron (edited June 24, 1999).]
Quote Reply
Re: Sub-Categories for Links In reply to
hm... yea..

after:

Code:
if ($#{$subcategories{$subcat}} >= 0 && $description =~ /^SUB.*/) {
$v = 0;
# $output .= qq~<$font_small>~;
foreach $subcatsub (sort @{$subcategories{$subcat}}) {
$suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
if ($subcatsub =~ m,.*/([^/]+)$,) { $subcategory_name = &build_clean($1); } else { $subcategory_name = &build_clean($subcatsub); }
$output .= qq~~ if ($description =~ /2$/ | | $v eq "0");
$output .= qq~ ~ if ($description =~ /2$/);
$output .= qq~<FORM name = "form"><SELECT NAME="site" SIZE=1 onChange ="formHandler(this.form)"><option value="">--Select a Subcategory--~ if
($description =~ /3$/ && $v eq "0");
$output .= qq~<a href="$suburl">$subcategory_name</a>~ if ($description =~ /1$/ | | $description =~ /2$/);
$output .= qq~<option value="$suburl">$subcategory_name~ if ($description =~ /3$/);
$output .= qq~, ~ if ($description =~ /1$/ && $v ne $#{$subcategories{$subcat}});
$output .= qq~</select></form><BR>~ if ($description =~ /3$/ && $v eq $#{$subcategories{$subcat}});
$v++;
}

and before the else {
put something like:

Code:
elsif ($description =~ /^SUB.*/) {
$output .= qq~<FORM name = "form"><SELECT NAME="site" SIZE=1 onChange ="formHandler(this.form)"><option value="">--Select a Subcategory--~ if ($description =~ /3$/);
$output .= qq~<option value="none">None~ if ($description =~ /3$/);
}

this is off the top of my head.. i haven't tried it, so sorry if it doesn't work.. tell me if it doesn't work.. this will elminate the SUB1 and SUB2 from posting SUB1 and SUB2 as a description... but it will put an option thing with None in it for SUB3

Thanks!
Jerry

[This message has been edited by widgetz (edited June 24, 1999).]
Quote Reply
Re: Sub-Categories for Links In reply to
Ok, I got that to work. Even works on subdirectories. Here is what I have:
Code:
if ($#{$subcategories{$subcat}} >= 0 && $description =~ /^SUB.*/) {
$v = 0;
# $output .= qq~<$font_small>~;
foreach $subcatsub (sort @{$subcategories{$subcat}}) {
$suburl = "$build_root_url/" . &urlencode($subcatsub) . "/";
if ($subcatsub =~ m,.*/([^/]+)$,) { $subcategory_name = &build_clean($1); } else { $subcategory_name = &build_clean($subcatsub); }
$output .= qq~~ if ($description =~ /2$/ &#0124; &#0124; $v eq "0");
$output .= qq~ ~ if ($description =~ /2$/);
$output .= qq~<font face="Arial" size=1><FORM name = "form"><SELECT NAME="site" SIZE=1 onChange ="formHandler(this.form)"><option value="">--Select a Subcategory--~ if ($description =~ /3$/ && $v eq "0");
$output .= qq~<a href="$suburl">$subcategory_name</a>~ if ($description =~ /1$/ &#0124; &#0124; $description =~ /2$/);
$output .= qq~<option value="$suburl">$subcategory_name~ if ($description =~ /3$/);
$output .= qq~, ~ if ($description =~ /1$/ && $v ne $#{$subcategories{$subcat}});
$output .= qq~</select></form>~ if ($description =~ /3$/ && $v eq $#{$subcategories{$subcat}});
$v++;
}
$output .= qq~</font>~;
}
elsif ($description =~ /^SUB.*/) {
$output .= qq~<font face="Arial" size=1><FORM name = "form"><SELECT NAME="site" SIZE=1 onChange ="formHandler(this.form)"><option value="">--Select a Subcategory--~ if ($description =~ /3$/);
$output .= qq~<option value="">None</select></form>~ if ($description =~ /3$/);
}
else {
$output .= qq~<dd><font face="Times New Roman" size=1>$description</font>~ if (!($description =~ /^[\s\n]*$/));
}

Next I think I will declare some variables and clean up my code. Smile

Aaron

------------------
www.serve.com/garden/geosearcher



Quote Reply
Re: Sub-Categories for Links In reply to
Hello,

This should work with templates now? What is the URL of a site with this working with templates please. Please let me know when this is polished and finished up so we can try it again. Will need detailed insert instructions again. Thank you for all the hard work.
Quote Reply
Re: Sub-Categories for Links In reply to
Greetings All!

I copied Aarons code at the ned of this conversation and here is the error I get. I am using snap clone templates.

Error including libraries: syntax error at /home/nzcid/cgi-bin/links2/admin/site_html_templates.pl line 387, near "| |"
syntax error at /home/nzcid/cgi-bin/links2/admin/site_html_templates.pl line 390, near "| |"
Unmatched right bracket at /home/nzcid/cgi-bin/links2/admin/site_html_templates.pl line 437, at end of line
syntax error at /home/nzcid/cgi-bin/links2/admin/site_html_templates.pl line 437, near "}"

Make sure they exist, permissions are set properly, and paths are set correctly.

Any assistance to get this working would be great. I like what Aaron has done on his site with the sub-categories.



------------------
http://www.nzcid.godzone.net.nz
New Zealand Christian Internet Directory

Quote Reply
Re: Sub-Categories for Links In reply to
find all the "&#0124; &#0124;"s and change them so they don't have a space in the middle..

the message board some reason changes it so it has a space in the middle..

Jerry
Quote Reply
Re: Sub-Categories for Links In reply to
i don't need it... (cause the max categories i have is 4 Smile...

but i guess i can do it.. Smile

(in a good mood.. lol) ok.. hold on and check back soon..

Jerry
Quote Reply
Re: Sub-Categories for Links In reply to
Umm....
Widgetz the mod you made is great. but i have a whole lot of links in one of my categories and the list just goes on and on and on...quite ugly. Is there anyway you can implement the 'more...' function?

------------------
_________________________
Regards,

Gian Wilson
The Hip Hop Network
http://www.hiphopnetwork.cjb.net
Get Your FREE PRIVATE PERSONAL e-mail address at http://www.hiphopnetwork.zzn.com
Quote Reply
Re: Sub-Categories for Links In reply to
that actually took me awhile.. i thought i had it.. but i didn't even test it out.. and then i reread the code.. and oh boy.. Smile

anyways here is the code:

Code:
if ($#{$subcategories{$subcat}} >= 0 && $description =~ /^SUB.*/) {
$v = 0;
$sub_length = "";
$output .= qq~<small>~;
foreach $subcatsub (sort @{$subcategories{$subcat}}) {
$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~<br>~ if ($description =~ /2$/ | | $v eq "0");
$output .= qq~&[nbsp];&[nbsp];~ if ($description =~ /2$/);
$output .= qq~<a href="$suburl">$subcategory_name</a>~;
$v++;
}
}
$output .= qq~</small>~;
}
else {
$output .= qq~<dd><span class="descript">$description</span></dd>~ if (!($description =~ /^[\s\n]*$/));
}

follow the instructions from the original.. REMEMBER to change "| |"s so that they don't have a space in the middle... and the "&[nbsp];" so they don't have the "["s and "]"s...

you will have to create a new variable in "links.cfg"

put

Code:
$subcat_length = "30";

and set the number to the number of characters you want to show up.. Smile

hope that helps you..

Jerry

[This message has been edited by widgetz (edited July 08, 1999).]
Quote Reply
Re: Sub-Categories for Links In reply to
hi.. i just made a page for it:

http://www.widgetz.com/links-mod.html

Smile
> >