Gossamer Forum
Home : Products : Links 2.0 : Customization :

SUBCATEGORIES LIKE YAHOO v2

(Page 1 of 2)
> >
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
> >