Gossamer Forum
Home : Products : Links 2.0 : Customization :

SUBCATEGORIES LIKE YAHOO v2

Quote Reply
SUBCATEGORIES LIKE YAHOO v2
Hi..

Recently, I've been working with an SQL version of my copy of Links2 and I have decided to just switch over.. So I am going to start releasing some mods that I never intended to release..

Starting with Subcategories Like Yahoo v2..

I made this quite awhile ago.. when a template user emailed me with an error.. he had thought it was usable like this:

SUB1, SUB2, SUB3

and it would display the 3 subcategories.. i decided that my version was just too simple and should be changed.. as i changed i noticed how "bad" my old code was.. hehe Wink

here is version 2..

Code:
if ($description =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($description, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $description);
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($description eq "ALL" && $#subcatsub == 0) ?
($_ =~ m,.*/([^/]+)$, and $category_name = &build_clean($1)) :
($_ eq "$subcat/$category_name" or next);
if ($style eq "1") {
$length += length($category_name);
($length > $subcat_length) and last;
}
if ($s > 0) {
$output .= qq~, ~ and $length += 2 if ($style eq "1");
$output .= qq~<br>~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~ ~ if ($style eq "2");
$output .= qq~<a href="$url">$category_name</a>~;
$s++;
last if ($description ne "ALL" && $#subcatsub > 0);
}
}
undef $length;

if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~..~ if ($style eq "1");
}
}
else { $output .= qq~$description~ if (!($description =~ /^[\s\n]*$/)); }

replace it with:

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

of course.. in links.cfg add this:

Code:
$subcat_length = 40;

in site_html.pl.. it's the same thing in site_html_templates.pl except the qq~.....~; are qq|.....|;

HOW TO USE?

well.. i will get to this more detailed when i update the links mod page for it.. (sooner or later).. but here is a brief description..

still.. 2 styles..

style 1

CATEGORY (x)
subcategory1, subcategory2, subcategory3..

style 2
CATEGORY (x)
subcategory1
subcategory2
subcategory3

well.... now it doesn't need to be in alphabetical.. you can specify any order to list them..

in the description of the category.. input one of these:

(ALL)1

lists all (alphabetical.. up to subcat_length) in style 1

(ALL)2

lists all (alphabetical) in style 2

(Games|Utilities|Hacks)1

lists:

Games, Utilities, Hacks

and ".." if there are more than 3 subcategories in that category..

(Games|Utilites|Hacks)2

lists

Games
Utilities
Hacks

also.. this version will check to see if the category exists.. if not.. it skips it so it won't print a dead category..

tell me if you are successful installing it..

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
you may want to add:

Code:
@subcatsub, $length, $s

to the MY tag at the top of the routine:

Code:
my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i, @subcatsub, $length, $s);

jerry

[This message has been edited by widgetz (edited October 02, 1999).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Nice one...the added flexibility of controlling cat order makes it a lot easier to organize topics. Thanks Jerry!
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Hey Jerry....You're the man....You want to team up to create a major search engine? I need to purchase the SQL version so I can play with it....but, then I want to tie the SQL part into an Oracle dBase......for unlimited links and categories.........let me know.... I'll be working on the first steps. I've got an Oracle programmer....we just need to purchase the software....which is going to cost over 10 grand......then tie it all together....Could be a good start for you.....
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
rdmille, contact me about it. It seems like what im planning/working on now.

Jim
jimmacr@earthlink.net
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
no thanks..

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Jerry, do you have a homepage?

------------------
- Jonathan Gamble
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Hi,

Back on Jerry's page where the original Yahoo subcategories code is posted, http://www.widgetz.com/...ubcategories1-t.html , he gives the following 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|  | 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]*$/));
}


This obviously is not the same as what is posted above under "here is version 2."

However, Jerry mentions that we should replace what is above (here is version 2)with
Code:
$output .= qq~<dd><span class="descript">$description</span></dd>~ if (!($description =~ /^[\s\n]*$/));

I'm not sure how to approach this.

Is "here is version 2" the update, or is the line below it the update?

Why is "here is version 2" different from what is posted at the Resources Center?

Many thanks for your help. Smile




------------------
www.armynavy.com
MilitarySurplus Ring






[This message has been edited by TrainedMonkey (edited October 07, 1999).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
just go backwards on the steps on the original and then do this one Wink

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Thanks.

------------------
www.armynavy.com
MilitarySurplus Ring




Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Hello, it seems that the script recognize the "|" in (Games|Hacks)1 as a sperator for me, any idea?
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
links should change | to ~~.. if not.. then you messed links up Wink

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Jerry and gang,

I've had no luck on your modification to the Yahoo subcategories modification. Can you take me from the top, with Links 2.0 out of the package (as if I had never installed the original modification in the first place)? I'm just a confused individual!

Thanks!

John

Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
hmm.. ok

find..

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

in site_html.pl.. or if you use templates.. it's the same except the ~'s are |'s

and then replace it with:

Code:
if ($description =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($description, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $description);
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($description eq "ALL" && $#subcatsub == 0) ?
($_ =~ m,.*/([^/]+)$, and $category_name = &build_clean($1)) :
($_ eq "$subcat/$category_name" or next);
if ($style eq "1") {
$length += length($category_name);
($length > $subcat_length) and last;
}
if ($s > 0) {
$output .= qq~, ~ and $length += 2 if ($style eq "1");
$output .= qq~<BR>~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~ ~ if ($style eq "2");
$output .= qq~<A href="$url">$category_name</A>~;
$s++;
last if ($description ne "ALL" && $#subcatsub > 0);
}
}
undef $length;
if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~..~ if ($style eq "1");
}
}
else { $output .= qq~$description~ if (!($description =~ /^[\s\n]*$/)); }

then in links.cfg.. add:

Code:
$subcat_length = 40;

and then follow those other instructions.. in the first message..

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
jerry,

thanks for the reply! things are working just fine now. I do have one question on formatting though: I'm using style 1 (exactly like Yahoo), but my subcategories are starting up by the main categories:

ACADEMIC RESEARCH Journals,
Databases, Scholarship...

instead of:

ACADEMIC RESEARCH
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
jerry,

thanks for the reply! things are working just fine now. I do have one question on formatting though: I'm using style 1 (exactly like Yahoo), but my subcategories are starting up by the main categories:

ACADEMIC RESEARCH Journals,
Databases, Scholarship...

instead of:

ACADEMIC RESEARCH
Journals, Databases, Scholarship...

Any ideas as to how to adjust this formatting issue?

thanks again!

john
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
just put a <br>

in this line.. above the mod..

Code:
$output .= qq|</dt>|;

i'm guessing you use templates.. cause only people that use templates don't know that.. cause it's CGI not a .html file..

so it would look like

Code:
$output .= qq|</dt><br>|;

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
jerry,

actually, I'm not using templates, but I found the spot -- looks great!

Thank you.

John
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
jerry (or anyone for that matter),

I've come across another issue with your modification. It looks as though there is an extra space being added in the subcategories.

ACADEMIC RESEARCH
Music Journals, etc...

the whole thing is underlined, so it doesn't look as bad as it does above, but nonetheless, is there anything that might be causing this? I'm adding subcategories in the links administration panel as it instructs:

Academic_Research/Music_Journals

is there some problem with the conversion of the _ character?

John
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
i don't understand what you mean.. are you saying that it's posted like

Music Journals

instead of:

Music_Journals

if so.. it's suppose to do that.. build_clean cleans out the _s for display.. the _s are used for the DIRs because of the fact you can't have a space in a DIR.. (unless you type in %20 or something)..

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
jerry,

no, not exactly...

it's printing an extra space, like

Music Journals

it just looks awkward...

the whole thing is underlined, as it is a link, so the underscore blends in with the underline. It's just that extra spacing...

John
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
I just looked at the posting I wrote, and the extra space is not appearing in between the words. but there is an extra space..

John
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
make sure this is your build_clean in your db_utils.pl is like this:

Code:
sub build_clean {
# --------------------------------------------------------
# Formats a category name for displaying.
#
my ($input) = shift;
$input =~ s/_/ /g; # Change '_' to spaces.
$input =~ s,/, : ,g; # Change '/' to ' : '.
return $input;
}

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Jerry...
excellent work, and I do appreciate it.
Can you take a look when you get a chance and see if you can tell what I am doing wrong?
http://www.stand318.com/links/pages/

the subcategories aren't showing up on the main page...
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
most likely you typed the name wrong.. change it to (ALL)1 and see if it display anything..

second reason may be cause you didn't add the subcat_length to links.cfg

make sure you type the name of the subcategory right.. not the WHOLE thing.. just the name.. like

Test

NOT

/Cat/Sub/That/This/Test

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
I am posting the text of my problem child at: http://stand318.com/site_html_templates.txt
if someone wants to take a gander at what I have done wrong...
muchas gracias amigos,

Allen
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
 
Quote:
most likely you typed the name wrong.. change it to (ALL)1 and see if it display anything..

I am now getting 2 dots where the subcategories should be displayed on the front page.

Quote:
second reason may be cause you didn't add the subcat_length to links.cfg

that part I did

Quote:
make sure you type the name of the subcategory right.. not the WHOLE thing.. just the name.. like

Test

NOT

/Cat/Sub/That/This/Test

I am not sure I follow you on this simple request. The help file for links says to type:
"maincategory/subcategory" in the name field.
You are saying to just type:
"subcategory" in the name field.
When I do this, it makes "subcategory" into a main category...

any help would be appreciated...
the url again is:
http://www.stand318.com/links/pages/

Sincerely,

Allen


Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
ok.. the error will only occur in TWO things.. i am sure.. ok? cause i did make the mod.. heh


anyways.. the first is something i don't think anyone would missout.. but JUST TO MAKE SURE..

Code:
$subcat_length = 40;

into links.cfg.. AND UPLOAD (of course Wink)

then the second could be a common mistake.. but i haven't heard of it..

the script checks to see if the subcategory you type in exists..

so when you put

Code:
(Sub1|Sub2|Sub4|Sub3)1

into the DESCRIPTION field of the category.. in this case let's say the category is called CAT..

so basically you are saying that

CAT/Sub1
CAT/Sub2
CAT/Sub4
and
CAT/Sub3

are valid categories.. you can't type

Code:
(CAT/Sub1|CAT/Sub2|CAT/Sub4|CAT/Sub3)1

it will think you are looking for

CAT/CAT/Sub1 etc..

ok.. i just reread your post and the first answer you gave me tells me everything..

you didn't edit your links.cfg.. you've got to add the $subcat_length=40; in.. or it will print 0 characters and then the .. (the .. only comes in if there are more subcategories than printed)

so since the ".." came in.. that means you must have at least one subcategory.. telling me that it just completely stopped printing cause you have subcat_length set to 0 or didn't upload it..

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
 
Firstly... I want to thank Jerry for taking the time to respond to my posts.
In the links.cfg file I had:
$subcat_length = '40';
I am not sure where the extra ''s came from, but I fixed those and am still getting the same results. When I click on "build all", it does recognize that the category "music" does have 3 subcategories in record_labels, artists, and radio_stations... but for some reason it still gives me only the '..' under the main category on the front page.
I am not sure where I am making the mistake... as I am sure others are getting the mod to work, so the problem must be something where *I* am not doing something right.
I have what my categories and subcategories look like posted here if someone has time to look and see if I am entering them wrong...
http://www.stand318.com/admin1.htm

merci bien, mon ami,

Allen
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
yea! Smile

that's the best piece of info i could get to help you.

you don't put "1" behind each subcategory...

Smile

only outside of the ()1 <--

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Mui bueno...:-) that fixed it...

Thanks again for your help Jerry... very appreciated...

Allen
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Hey everyone.
I had categories without subcats, but was planning to add them later. When I entered the (ALL)1 in the descript field, it would actuall print (ALL)1 as the description where the subcats would be listed. I understand this was intended as a feature, but since I don't intend on describing the cats ever i removed this line.

Code:
else { $output .= qq~$description~ if (!($description =~ /^[\s\n]*$/)); }

problem fixed.

------------------
[URL=http://bartour.hypermart.net]BarTourOnline.com[/url]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Hey, that mod to the mod of the mod is a great mod.

I have some categories that didnt have SubCategories, and removing that else statement did tha trick.

Drop tha chalupa!

- Mr. Undies
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Hi guys. I just been trying to install Yahoo look-like sub categories to my links2, And I had no luck. I tried three times with different scripts bud its not working, and don’t understand why. Usually I’m getting scripts right pretty ease, but not this time.
I tried Jerry’s version 1 and 2 but i got no luck. First of all how do you add subcategory to category from admin panel I’m not using Yahoo templates, i’m using Slick Links Template , is there any difference getting subcategories right ?
Please can you give me the scrip and some detailed decryption how to that.
Thank you for you help.

Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
if you don't know how to add subcategories.. then this script won't output anything..

at the bottom of the main admin page there is something that tells you how to add a subcategory..

jerry
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Any of the following codes should be changed if I'm using non-english mode?
Need Help ......


Qoute:....

hmm.. ok

find..

code:


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



in site_html.pl.. or if you use templates.. it's the same except the ~'s are |'s

and then replace it with:

code:


if ($description =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($description, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $description);
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($description eq "ALL" && $#subcatsub == 0) ?
($_ =~ m,.*/([^/]+)$, and $category_name = &build_clean($1)) :
($_ eq "$subcat/$category_name" or next);
if ($style eq "1") {
$length += length($category_name);
($length > $subcat_length) and last;
}
if ($s > 0) {
$output .= qq~, ~ and $length += 2 if ($style eq "1");
$output .= qq~<BR>~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~ ~ if ($style eq "2");
$output .= qq~<A href="$url">$category_name</A>~;
$s++;
last if ($description ne "ALL" && $#subcatsub > 0);
}
}
undef $length;
if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~..~ if ($style eq "1");
}
}
else { $output .= qq~$description~ if (!($description =~ /^[\s\n]*$/)); }

Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
In widgetz' instructions, he mentions:

Quote:
(Games|Utilities|Hacks)1

lists:

Games, Utilities, Hacks

and ".." if there are more than 3 subcategories in that category..

I have a category, Fishing, with 4 subs. When I set up (Tackle|Boats)1, the output is:

Fishing (X)
Tackle, Boats..

However, when I set up (Tackle|Boats|Guides)1, the output is:

Fishing (X)
Tackle, Boats, Guides

There are no dots - ".." - even though there are more than 3 subs.

Would anyone have any ideas? The code that I'm using is not modified except to change the ~ to |

Thanks for any help. Smile
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
It probably is related to the $subcat_length variable configuration.

Try using a higher value like 55.

So, it should look like:

Code:
$subcat_length = 55;

Regards.

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Thanks for your suggestion, AnthroRules. I bumped it up to 55, but no go. I'll keep hacking. Has anyone else run into this?

BTW, AnthroRules, how did you get the subcats on your category pages to have different spacing than the categories on your links home page?

I like the single spacing and different font on the category page for the subs. If you get a chance, I'd love to know how to do it. Thanks.

DT

[This message has been edited by DogTags (edited April 28, 2000).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2 In reply to
Jerry You Wrote
**********
into the DESCRIPTION field of the category....

****************

Please Oh Please Tell me more about this area of interest.
and give examples...

This just may be my problem....

Q- I need to type into the discription field when making a category??
I don't recall reading this any where...

~~~~~~
This is where I'm at... with More Questions

The Links2 codes work great and I went step by step on Yahoo SubCat Mod Ver2.

So I located the problem in last step of Yahoo SubCat MOD
which is the last step in instrutions...

Last Step...
# Then we print out the name linked, new if it's new, and popular if its popular.

If I add this last change in code I lose categorys only (link amount is visble)

Q- What could it/I be missing??

If I use the codes you listed...
http://gossamer-threads.com/scripts/resources/Attach/1072-MyMod.txt

I get an error about a missing bracket and/or unmatch right bracket = } at whatever line..

I take it out and codes work fine just no Sublisting on Home page...

Q- b /b where is it placed...
`Before and after on each line?
`b at top line and /b at bottom?
`or is b /b on a line by them selves?

Q- if so which line?

Q- Top of list or bottom?



PS...
Thanks for freely contributing...

Peace
2Dum2no






Quote Reply
Re: [2Dum2no] SUBCATEGORIES LIKE YAHOO v2 In reply to
Where exactly do I add $subcat_length = 55;?
And how come when I put the (Sub1|Sub2|Sub4|Sub3)1, that's how it shows up on the page?