Gossamer Forum
Home : Products : Links 2.0 : Customization :

SUBCATEGORIES LIKE YAHOO v2.1

(Page 1 of 6)
> >
Quote Reply
SUBCATEGORIES LIKE YAHOO v2.1
A Mod to the Yahoo Style SubCategory Listings Mod by Widgetz.

I wanted to use the Yahoo style Sub-Category listings on my site, but I also wanted to keep the
ability to use the category descriptions. So I came up with this mod to Widgetz Mod to allow
just that.

Notes:
1. Remember to backup files to be edited before proceeding.
2.This Mod assumes no previous mods are installed and you are using templates.
3.If you have an existing categories.db file, you should review information
on Bobsie's upgrade script at
www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/001090.html .
This will help you add the new field spacing to your categories.db.

links/cgi-bin/admin/category.def

Find this section: (it's at the top)

Code:
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Name => [1, 'alpha', 40, 75, 1, '', '^[\w\d/_-]+$'],
Description => [2, 'alpha', '40x3', 500, 0, '', ''],
Related => [3, 'alpha', 0, 255, 0, '', ''],
'Meta Description' => [4, 'alpha', 40, 75, 0, '', ''],
'Meta Keywords' => [5, 'alpha', 40, 75, 0, '', ''],
Header => [6, 'alpha', 40, 75, 0, '', ''],
Footer => [7, 'alpha', 40, 75, 0, '', '']
);

Palace this line under the last entry in the list just before the );
Code:
SubCatStyle => [8, 'alpha' ,40, 100, 0, '(ALL)1', '']
^ ^
Filed ID Default Entry

The field id, in this case 8 should be changed to reflect the fields sequence in your database.
Don't forget to place a comma at the end of the entry on the line above SubCatStyle. You can indicate
a default style by placing one of the styles from the bottom of this post in the Default Entry section
of the field definition.

links/cgi-bin/admin/site_html_templates.pl

Find this:
Code:
foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];

Place this just below it
Code:
($subcatstyle) = @{$category{$subcat}}[8];

Change the filed ID to match the one you entered in the category.def

Find this comment line:
Code:
# Then we print out the name linked, new if it's new, and popular if its popular.

Replace with:
Code:
# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<a class="catlist" href="$url">$category_name</a> <font class="catlist">($numlinks)</font> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|<BR>|;

if ($subcatstyle =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($subcatstyle, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $subcatstyle);
$output .= qq~    ~ if ($style eq "1");
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($subcatstyle 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~ ~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~<LI>~ if ($style eq "2");
$output .= qq~<a class="subcat" href="$url">$category_name</a>~;
$s++;
last if ($subcatstyle ne "ALL" && $#subcatsub > 0);
}
}
undef $length;
if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~...~ if ($style eq "1");
}
$output .= qq~<BR>~;
}
else { }}

# Don't forget to end the table..
$output .= "</td></tr></table></div>\n";
return $output;
}

If you wish the catagory despcription to be displayed rather than the catagory name replace

Code:
$output .= qq|<a class="catlist" href="$url">$category_name</a> <font class="catlist">($numlinks)</font> |;

with

Code:
$output .= qq|<a class="catlist" href="$url">$description</a> <font class="catlist">($numlinks)</font> |;

links/cgi-bin/admin/links.cfg

Find this section (it's close to the bottom)
Code:
# Site Title, the default title to use. You should really spend some time customizing
# the directory though!
$build_site_title = 'Gossamer Threads';

Insert this bellow it
Code:
# Subcategory Length, the maximum length of the subcategories added into Links.
$subcat_length = '30';

That's it for the CGI Work. Now you need to add the place holder for the new field to your
category database (links/cgi-bin/admin/data/categories.db).
To do this just add a | (see note 3 above) to the end of each record in your database.

To use this mod indicate what style of subcategory listing you would like by entering one of the
styles below in the SubCatStyle filed in the Modify Category screen of the Links Admin page.

Code:
Style Types...

Horizontal Layout (alphabetical.. up to subcat_length)
(ALL)1
Category (#)
Subcategory1, Subcategory2, Subcategory3...


Vertical Layout (alphabetical)
(ALL)2
Category (#)
* Subcategory1
* Subcategory2
* Subcategory3
* Subcategory4


Horizontal Layout (ordered by you)
(Games|Utilities|Hacks)1
Category (#)
Games, Utilities, Hacks


Vertical Layout (ordered by you)
(Games|Utilites|Hacks)2
Category (#)
* Games
* Utilities
* Hacks

That should do it. If you have problems I will do my best to help you. Just post them to this
thread and I will respond as quickly as possible.


----------------------
Bert Gaddis
SysOp, The-BBS.COM
www.the-bbs.com
----------------------


[This message has been edited by Kraken (edited February 29, 2000).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Hey..

I have followed every instruction just like you put it. However all I get on my site is the categories listed like normal, no subcategories appear. I edited the site_html.pl file
and also the
site_html_templates.pl and the
category.def and the
links.cfg and last but not least the category.db file. I do have a new entry listed in my modify for categories, but the listing obviously doesn't work because it won't list the file.
HELP!!!!?!?!? :- )
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
DanS,

Lets check a few things here. make sure you haved placed $subcat_length = '30'; in your links.cfg file and that your are putting one of the subcat styles in the SubCategoryStyle field in the category modify form. If you have defined a default style in the category.def this only effects new categories you create, not existing categories.

As a test, enter (All)1 in the SubCategoryStyle field for your first category sith subs. Then "Build All". If you made the code changes correctly you should see your caegories listed like Yahoo!



------------------
===========================
Bert Gaddis
Sysop, The-BBS.COM

http://www.the-bbs.com
===========================
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Howdy,

Ok. I now have the subcategories showing, which is GREAT. Thanks.. BUT..
my site, (http://www.creativesystem.com/slway/)
now has each next category in the list INDENTED
What did I do wrong?? lol
Here is the code that I put into my site_html_templates.pl
-----------------------BEGIN--------
# 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> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|</dt>|;
if ($subcatstyle =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($subcatstyle, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $subcatstyle);
$output .= qq~ ~ if ($style eq "1");
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($subcatstyle 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~ ~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~<LI>~ if ($style eq "2");
$output .= qq~<a class="subcat" href="$url">$category_name</a>~;
$s++;
last if ($subcatstyle ne "ALL" && $#subcatsub > 0);
}
}
undef $length;
if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~...~ if ($style eq "1");
}
$output .= qq~<BR>~;
$output .= qq|</dl>|;
}}

# Don't forget to end the unordered list..
$output .= "</td></tr></table></div>\n";
return $output;
------------------END-----------
I listed the code before what I pasted and after so that you would know in what section I pasted it :- )


Thanks,
Daniel S.

[This message has been edited by DanS (edited February 12, 2000).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Dan,

My bad, I modifyed some additional code. Here is the whole code segmant starting from the #comment line from.

Code:
# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<a class="catlist" href="$url">$description</a> <font class="catlist">($numlinks)</font> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|<BR>|;

if ($subcatstyle =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($subcatstyle, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $subcatstyle);
$output .= qq~ ~ if ($style eq "1");
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($subcatstyle 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~ ~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~<LI>~ if ($style eq "2");
$output .= qq~<a class="subcat" href="$url">$category_name</a>~;
$s++;
last if ($subcatstyle ne "ALL" && $#subcatsub > 0);
}
}
undef $length;
if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~...~ if ($style eq "1");
}
$output .= qq~<BR>~;
}
else { }}

# Don't forget to end the table..
$output .= "</td></tr></table></div>\n";
return $output;
}

I took out the Definition list and forgot to show that in my code.

Sorry

------------------
===========================
Bert Gaddis
Sysop, The-BBS.COM

http://www.the-bbs.com
===========================
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Now I am back to no subcategories, but the indents are fixed.. .grrrrr :- )
Here's my code:
-----------BEGIN------------
# Then we print out the name linked, new if it's new, and popular if its popular.
$output .= qq|<a class="catlist" href="$url">$description</a> <font class="catlist">($numlinks)</font> |;
$output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff);
$output .= qq|<BR>|;
if ($subcatstyle =~ m,^\(([^\)]+)\)(\d)$, && $#{$subcategories{$subcat}} >= 0) {
($subcatstyle, $style) = ($1, $2);
$s = 0;
@subcatsub = split (/\|/, $subcatstyle);
$output .= qq~ ~ if ($style eq "1");
foreach $category_name (@subcatsub) {
foreach (sort @{$subcategories{$subcat}}) {
($subcatstyle 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~ ~ if ($style eq "2");
}
$url = "$build_root_url/" . &urlencode($_) . "/";
$output .= qq~<LI>~ if ($style eq "2");
$output .= qq~<a class="subcat" href="$url">$category_name</a>~;
$s++;
last if ($subcatstyle ne "ALL" && $#subcatsub > 0);
}
}
undef $length;
if ($s < $#{$subcategories{$subcat}}) {
$output .= qq~...~ if ($style eq "1");
}
$output .= qq~<BR>~;
}
else { }}
# Don't forget to end the table..
$output .= "</td></tr></table></div>\n";
return $output;
}

1;
-----------------END--------------



Ideas??
Daniel S.

[This message has been edited by DanS (edited February 12, 2000).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Dan,

Lets have a look at your home.html template. If you could email (bgaddis@the-bbs.com) it to me I'll look it over.




------------------
===========================
Bert Gaddis
Sysop, The-BBS.COM

http://www.the-bbs.com
===========================
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Dan,

I have replaced my site_html_templates.pl with yours and all works just fine. I retraced everything I could tink of that could be differant from my syste to yours and the only thing I can come up with is the field ID in the category.def file.

Check to make sure that the field ID in both the site_html_templates.pl and category.def match.

Code segment from site_html_templates.pl
Code:
foreach $subcat (sort @subcat) {
($description) = @{$category{$subcat}}[2];
($subcatstyle) = @{$category{$subcat}}[8];
^
Field ID

Code segment from category.def
Code:
# Definition of your database file.
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Name => [1, 'alpha', 40, 75, 1, '', '^[\w\d/_-]+$'],
Description => [2, 'alpha', '40x3', 500, 0, '', ''],
Related => [3, 'alpha', 0, 255, 0, '', ''],
'Meta Description' => [4, 'alpha', 40, 75, 0, '', ''],
'Meta Keywords' => [5, 'alpha', 40, 75, 0, '', ''],
Header => [6, 'alpha', 40, 75, 0, '', ''],
Footer => [7, 'alpha', 40, 75, 0, '', ''],
SubCatStyle => [8, 'alpha', 40, 100, 0, '(ALL)1', '']
);
^
Field ID

Regards



------------------
===========================
Bert Gaddis
Sysop, The-BBS.COM

www.the-bbs.com
===========================

[This message has been edited by Kraken (edited February 12, 2000).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Dan,

I see you have it working at http://www.creativesystem.com/slway . was the problem the field ID?



------------------
===========================
Bert Gaddis
Sysop, The-BBS.COM

http://www.the-bbs.com
===========================
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Kraken,
No I got tired of fooling with it after using many hours and not getting anywhere so I just used the old code from the MODS area..
I would have liked to use yours but I just couldn't get it to work.. :- )

Daniel S.
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
The problem might be that the following in links.cfg might have been added twice
Code:
# Subcategory Length, the maximum length of the subcategories added into Links.$subcat_length = '30';

If you already use widgetz' yahoo2 mod, you already have this in. It might not need to be added, as in the directions above.

HTH
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Kraken's 'Subcategories like Yahoo' is the first mod that I have installed for links so far. So it wouldn't be widgetz' yahoo mod. I had looked at that but hadn't installed it.. I have made my own template for the way my site looks.

Daniel S.

[This message has been edited by DanS (edited February 13, 2000).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
I've just noticed a couple of odd things in your code nad have a question.

This code appears to be incorrect because you are making a link to the description:

Code:
. $output .= qq|<a class="catlist" href="$url">$description</a> <font class="catlist">($numlinks)</font> |; $output .= qq|<small><sup class="new">new</sup></small>| if (&days_old($mod) < $db_new_cutoff); $output .= qq|<BR>|;

My question is that only two subcategories are showing up. Any idea why that would happen?
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
The reason that the link is to the description (correct me if I am wrong) is that field is where the sub-categories are stored.

To increase the number of sub-categories listed, you need to increase the value of the following variable:

Code:
$subcat_length = '30';

Like the following:

Code:
$subcat_length = '60';

This variable is the trigger variable that specifies the total length for sub-categories. So, if you want more sub-categories...increase the value.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------









Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
The description, in this case, IS the Category Name.

In admin, in your category description box, type in what you want the category name to say. Then, build.

The "description" shows up as a linked category name on your page.

[This message has been edited by DogTags (edited February 15, 2000).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Blue

On my site I wanted to provide more detailed explanations of the categories, but did not want to display both the category name and the description.

Kraken
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Kraken,

Nice Mod...One thing that I would add to your instructions is that if people have an existing categories.db file, they will need to add the new field spacing in their categories.db file using Bobsie's upgrade.pl file.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------









Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Thanks Eliot,

Coming from you that means alot, but the bulk of the work was done
by Widgetz. I took your suggestion and added a link to Bobsie's
upgrade script.

Chow,



------------------
===========================
Bert Gaddis
Sysop, The-BBS.COM

http://www.the-bbs.com
===========================
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Good...it will help novice users.

If more people have success with this modification...you should add it to the Resource Center (yet crediting Widgetz and Bobsie for their contributions).

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------









Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Please help. I set up the Yahoo mod 2.1 on my site but now the categories dont appear on the built pages.

The admin page is here

http://www.students.f2s.com/cgi-bin/links/admin/admin.cgi

Username and pass: 12345

Thanks for your help.
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Rambo2,

I tryed to view your site but the username and password you provided didn't work.

Any how I think I know what the problem my be, if you specifyed a default SubCat Style in the record definition section of links.def this does not apply to currently existing records. You need to define a SubCat style such as (ALL)1, manualy for each existing Category and do not define any style for the SubCategory.



------------------
===========================
Bert Gaddis
Sysop, The-BBS.COM

http://www.the-bbs.com
===========================
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Hi me again. I fixed the problem. Sorry about before. Anyway the categories are showing up because I put the name in the description but the subcategories wont show up. Please help me.

The url to the admin script is:
http://www.students.f2s.com/cgi-bin/links/admin/admin.cgi

And the pages are at :

http://www.students.f2s.com/pages/

Thanks
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
sorry, could you help me and check my problems, my site is upgraded from english to chinese, but it doest not work till I change all the data as mentioned in your intro,
by the way, my admin page works well, and I have the subcatstyle field, and building all is correct, but my subcat does not show up

[This message has been edited by phandsome (edited February 20, 2000).]
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
Rambo2, phandsome,

Thinking I left something out of my instructions I built a new site
with a clean version of Links to test my mod.

I followed my own directions to the letter, and what do you know it
worked just as it should.

The only thing I can come up with that you may be missing is adding
the SubCatStyle field place holder into your categories.db file. If
you miss this step the sub-categories will not build, nor will links
generate an error.

I suggest that you read through the direction again and make the
correction to your categories.db file.

Regards


------------------
===========================
Bert Gaddis
Sysop, The-BBS.COM

http://www.the-bbs.com
===========================
Quote Reply
Re: SUBCATEGORIES LIKE YAHOO v2.1 In reply to
my problem is how can I add:
code:
--------------------------------------------------------------------------------

Style Types...Horizontal Layout (alphabetical.. up to subcat_length)(ALL)1 Category (#) Subcategory1, Subcategory2, Subcategory3...Vertical Layout (alphabetical)(ALL)2 Category (#) * Subcategory1 * Subcategory2 * Subcategory3 * Subcategory4Horizontal Layout (ordered by you)(Games|Utilities|Hacks)1 Category (#) Games, Utilities, HacksVertical Layout (ordered by you)(Games|Utilites|Hacks)2 Category (#) * Games * Utilities * Hacks

I have the SubCat Field


[This message has been edited by phandsome (edited February 21, 2000).]
> >