Gossamer Forum
Home : Products : Links 2.0 : Customization :

NEW Yahoo SubCats Mod

(Page 1 of 2)
> >
Quote Reply
NEW Yahoo SubCats Mod
I've seen loads of posts from people having trouble with Jerry's mod or not being able to find one so I wrote one :)

It is really short and simple, requires no extra fields or messing about.

You will need to add two new options into links.cfg....

$max_subs = X; # Number of subcategories to show on main page
$hyperlink = 1; # 1 to hyperlink subcats or 0 for text

Then all you need to do is open up site_html_templates.pl and in site_html_print_cat replace:

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

With:

Code:
$output .= qq|</dt>|;
$output .= qq|<br><small>| . qq|&nbsp;| x 4;

for (@{$subcategories{$subcat}}) {
if (m,^\Q$subcat\E/([^/]+)$,) {
$child = &build_clean($1);
if ($hyperlink) {
$output .= qq|<a href="$build_root_url/$subcat/$child/">$child</a>,|
}
else {
$output .= qq|$child,|
}
$j++;
if ($j == $max_subs) {
last;
$j = 0;
}
}
$j = 0;
}
chop $output;
$output .= qq|</small><br>|;
$output .= qq|<dd><span class="descript">$description </span></dd>| if (!($description =~ /^[\s\n]*$/));

Thanks :)



Last edited by:

PaulW: Dec 17, 2001, 1:02 PM
Quote Reply
Re: [PaulW] NEW Yahoo SubCats Mod In reply to
Hehe, this way will work too for those lazy people Laugh (although it won't allow you to turn hyperlinking on/off and control the number of sub-cats. It has sex appeal though.



my %foo = map { $_ => s,^\Q$subcat\E/([^/]+)$,&build_clean($1),e } @{$subcategories{$subcat}};
$output .= join ',', sort keys %foo;








Last edited by:

PaulW: Dec 17, 2001, 1:31 PM
Quote Reply
Re: [PaulW] NEW Yahoo SubCats Mod In reply to
Oh! Yes, it's working very .Smile



But don't you think it would be better to add links in subcategories.

like here: http://inmacau.com/ Wink


Quote Reply
Re: [delsio] NEW Yahoo SubCats Mod In reply to
Sorry Im not sure what you mean. That looks exactly the same.
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
I am having a small problem with this mod... it displays the sub catagories fine but I set $max_subs = 5 and it still displays all of the sub catagories.... what did I mess up?
Quote Reply
Re: [lucent] NEW Yahoo SubCats Mod In reply to
I did a few tests on my copy and changing $max_subs did limit the number displayed.

I'll have a play tommorrow and see if I can find the problem (its 1.20am now)
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
Mr. RedRum,

Things are not working very well for me.UnsurePirateFrown

The links in sobcategories are disabled. I already changed $hyperlink = 1; but I wasn't very happy!

I made nonenglish modifications, Is there any problem with that?
Quote Reply
Re: [delsio] NEW Yahoo SubCats Mod In reply to
I expect it is the non-english mod as there doesn't seem to be a problem with the hyperlinking code.

Last edited by:

RedRum: Dec 24, 2001, 4:44 AM
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
Do you have any proposal?
Quote Reply
Re: [delsio] NEW Yahoo SubCats Mod In reply to
Theres not much I can do/say. Ive not used the non-english mod so I don't know how it works, where it is installed, whether you installed it correctly.

On my copy changing $hyperlink to 1/0 switches hyperlinking on/off so I have to assume it works fine.
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
Oh yes!

I know what was wrong, everthing is okay now.

But tell me, the accents disappeared is that also because of nonenglish modifications?Crazy

Thanx!Wink
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
Hi Redrum,

I have tried posting here, but the editor dumps a bunch of html every time I include the code, no matter which editor I use (basic or advanced) or even including CODE tags. I've tried three times. I get great previews in the Basic Editor, but no button to post. The advanced editor gives me the post option, but it all comes through as an html mess, anyway I will attach the code as a txt attachment

I had the same problem with all the subcats being dumped. I think it is the position of the second $j=0 keeps resetting the subcat count every iteration. Attached in yahoomod.txt is what I did, which seemed to work (2 steps)

Regards,

Matt

Last edited by:

memobug: Jan 1, 2002, 4:42 PM
Quote Reply
Re: [memobug] NEW Yahoo SubCats Mod In reply to
Hi,

Thanks for the fix.


Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
oops. I keep having a problem with messages previewing okay, then I go to post and I get HTML spaghetti!

I think I found and corrected one additional bug in the original mod, plus another minor bug and opportunity to add a feature to make it more Yahoolike.

1) the bug: For some reason, subcategory names with pseudo-spaces like

Online_Magazines

were linking to the wrong page. The subcategory page had been built at
...links/Publications/Online_Magazines/

Tongue but this mod was sending it to
...links/Publications/Online%20Magazines/

WinkI fixed that by swapping in a _ for each space in the $child link.

2. The annoyance was that subcats like Online_Magazines were breaking in the category listing into Online
Magazines
WinkI fixed that by swapping in a nonbreaking space for the space

3. The opportunity for improvement was when there are more categories present than printed, it would be nice to have it print an ellipsis ... like

MAIN HEADING
subcat1,subcat2,subcat3...

So I added three lines to test and do that. I don't know much about Perl at all, but it seems to be working although inelegant, so I would appreciate it if you could have a look. I especially don't know why I had to print four periods to see three!

Here is the latest in the attachment It's working well for three or four displayed subcategories. If you would like to print many more it will need to break somewhere in the browser, so you should consider adding a space after the comma to let it do that! Yahoo seems to use three or four subcats, but it looks like they are counting characters to see how many will fit!

P.S. Go ahead and fix my code up. I know I am driving screws with a hammer







Last edited by:

memobug: Jan 3, 2002, 1:16 AM
Quote Reply
Re: [memobug] NEW Yahoo SubCats Mod In reply to
Hey thanks.

I addressed the %20 problem somewhere, it must have been another thread.

Anyway instead of using:

$mychild = $child; # copy $child to replace space with underscore
$mychild =~ s/[ ]/_/g; # replace space in subcat URL with underscore in link
$child =~ s/[ ]/&nbsp;/g; # replace space in subcat title with (nonbreaking!) space

you can just change:

$child = build_clean($1);

to

$child = $1;

Then for this bit:

Code:
if ($j == $max_subs) {
if (m,^\Q$subcat\E/([^/]+)$,) { # we're done but are there more subcats left?
$output .= '....' # print elipsis ... (why 4 to get 3?)
}; # continue on as before
last;
$j = 0;
}

....you can probably do:

Code:
if ($j == $max_subs) {
$output .= '.' x 4;
last;
$j = 0;
}

I've not tested that though so let me know if you have any success with it.
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
Hi! I'm a complete newbie, and don't know anything at all about Perl, really. I've successfully installed Links 2.0, and am trying to install the Yahoo style sub-categories mod that you posted in this thread (thank you!). I did get it to work, but I am having the same problems MemoBug mentioned - ALL of the subcats print, even though I specified only 2 in Links.cfg, plus I also get the %20 issue with spaces. I tried implementing the changes that MemoBug posted, as well as the additional changes you then posted, but when I use those, then try to rebuild, instead of rebuilding, it tells me I am trying to download the nph-build.pl file from the server. Obviously, something is going on, but I don't know enough about it to say what. I've searched through the forums, but haven't seen any other fixes for this, and all the other posts about Yahoo style subcategories seem much more confusing and difficult to implement. Can you help me?

Thanks so much for posting your mods in the first place, and sharing your knowledge!

Valerie
Valerie Williams
www.KnownWorldWeb.com
Quote Reply
Re: [valeriestw] NEW Yahoo SubCats Mod In reply to
>>instead of rebuilding, it tells me I am trying to download the nph-build.pl file from the server.<<

That means you made a syntax errror. Could you open the download and paste what it says?

Thanks.
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
Okay, here is what it says:

Error including libraries: Missing right bracket at d:/64.225.47.106/cgi-bin/links/admin/site_html_templates.pl line 434, at end of line syntax error at d:/64.225.47.106/cgi-bin/links/admin/site_html_templates.pl line 434, at EOF

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


I didn't know it would give me an error in that download, that's a good thing to know. I have also attached my site_html_templates.pl file as I think that is where the problem is. Thanks!
Valerie Williams
www.KnownWorldWeb.com
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
RedRum - I made those changes and it's working great. There's only one last fix that would make this perfect. Right now it's displaying an ellipse when we reach the $max_subs number. But when there are fewer total subcategories than $max_subs, the last one listed still has a comma after it. How can we get rid of that? I tried using an if statement based on $#child, but that didn't do much good. (Didn't think it would, actually, but figured I'd give it a shot.) Any thoughts?

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [davidziel] NEW Yahoo SubCats Mod In reply to
Could you show me the exact code you have please Angelic ?
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
Thanks for your help, and please excuse the formatting below (can't figure out how to get code to post properly in this forum):

sub site_html_print_cat {

# --------------------------------------------------------

# This routine determines how the list of categories will look.

# We now use a table to split the category name up into two columns.

# For each category you can use the following variables:

#

# $url : The URL to go to that category

# $category_name : The category name with _ and / removed.

# $category_descriptions{$subcat}: The category description (if any).

# $numlinks : The number of links inside that category (and subcategories).

# $mod : The newest link inside of that category.

#

my (@subcat) = @_;

my ($url, $numlinks, $mod, $subcat, $category_name, $description, $output, $i);

my ($half) = int (($#subcat+2) / 2);



# Print Header.

$output = qq|<table align="left" width="95%" border="0" cellspacing="0" cellpadding="5"><tr><td align="left" class="catlist" valign="top">\n|;



foreach $subcat (sort @subcat) {

($description) = @{$category{$subcat}}[2];



# First let's get the name, number of links, and last modified date...

$url = "$build_root_url/" . &urlencode($subcat) . "/";

if ($subcat =~ m,.*/([^/]+)$,) { $category_name = &build_clean($1); } else { $category_name = &build_clean($subcat); }

$numlinks = $stats{"$subcat"}[0];

$mod = $stats{"$subcat"}[1];

# We check to see if we are half way through, if so we stop this table cell

# and begin a new one (this lets us have category names in two columns).

if ($i == $half) {

$output .= qq|</td><td width="50%" align="left" class="catlist" valign="top">\n|;

}

$i++;



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

$output .= qq|<strong><a class="link" href="$url">$category_name</a></strong> <small class="numlinks">($numlinks)</small> |;

$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);

$output .= qq||;

$output .= qq|<br><small>| . qq||;

$j=0;

for (@{$subcategories{$subcat}}) {

if (m,^\Q$subcat\E/([^/]+)$,) {

$child = &build_clean($1);

if ($j == $#child) {

$output .= qq|<a href="$build_root_url/$subcat/$child/">$child</a>|;

}

else {

$output .= qq|<a href="$build_root_url/$subcat/$child/">$child</a>, |;

}

}

$j++;

if ($j == $max_subs) {

$output .= 'and more....';

last;

$j = 0;

}



}





chop $output;

$output .= qq|</small><br><br>|;

$output .= qq||;

}

# Don't forget to end the unordered list..

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

return $output;

}

1;


Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [davidziel] NEW Yahoo SubCats Mod In reply to
Right you need to change:

$child = &build_clean($1);

to

$child = $1;

The bold bits below don't seem to be doing anything :)

$output .= qq||;

$output .= qq|<br><small>| . qq||;

$child is a scalar so you won't be able to do $#child

The reason the comma is left is because you added a space after the comma in the code so the chop line won't work. So you'd either need to replace the chop line with...

chomp $output;
chop $output;

or.....

$output =~ s/[\s,]+$//;


Last edited by:

RedRum: Jan 7, 2002, 12:02 PM
Quote Reply
Re: [RedRum] NEW Yahoo SubCats Mod In reply to
Excellent! Thank you.

chomp $output;
chop $output;


didn't seem to do anything, but

$output =~ s/[\s,]+$//;

seems to have worked perfectly (although I have no idea what it means)...

As for:

$child = &build_clean($1);

I already knew about that, I just forgot to fix it after a recent cut and paste... And the empty output qq statements were just left over from previous edits - I wanted to save a place holder in case I needed to go back and fix it.

Anyway, everything is displaying perfectly now. Thanks for all your help.



Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [davidziel] NEW Yahoo SubCats Mod In reply to
>>$output =~ s/[\s,]+$//;

seems to have worked perfectly (although I have no idea what it means)... <<

It just strips out trailing commas, newlines, spaces etc...

Last edited by:

RedRum: Jan 7, 2002, 2:31 PM
Quote Reply
Re: [davidziel] NEW Yahoo SubCats Mod In reply to
Hi,

I've just had to install this mod for someone and the reason for the problem with it not limiting the number of subcategories shown is due to:

if ($j == $max_subs) {
last;
$j = 0;
}


...if you put $j = 0; before last, it should work Cool

...just a fix for anyone reading this thread.
> >