Gossamer Forum
Home : Products : Links 2.0 : Customization :

Different Categories Question (v2)

Quote Reply
Different Categories Question (v2)
Searching through the archives, I've seen a million category list display questions, but none of them are like mine.

It seems to be a fairly simple thing, but not for me. What I want is a routine to build a categories list using only my ROOT categories, and I want to use the list that builds as a token in every one of my pages, from the home page to the modify link form... global. (putting it in a menu bar down the left, typical stuff) I don't use subcategories at all, so I don't need any reference to them.

It strikes me as simpler than the original script, but I don't know how to do it. Right now the kludge I'm using is to make every one of my root categories related to every other, and I've edited the display of related categories so that it looks the same as my homepage category list (1 column, very simple)

Thanks for any help.
Phoenix
Quote Reply
Re: Different Categories Question (v2) In reply to
Phoenix,

Take a look at my site at www.BobsGoodStuffLists.net/BBS/ and look at the right side of my screen. Disregarding the sub-cats listed, is this what you are interested in?

Note from Bobsie: I know longer have this available so the link above does not show what it says it shows.

Last edited by:

Bobsie: Feb 13, 2006, 12:31 PM
Quote Reply
Re: Different Categories Question (v2) In reply to
Bobsie,
Yes, that would be perfect for my needs. Actually I stared long and hard at that yesterday while I was trying to figure out how to do this by myself and tried to find a mod sheet on your site for it since you've got them all written up so clearly. Couldn't find the mod sheet though.
Thanks
Phoenix
Quote Reply
Re: Different Categories Question (v2) In reply to
Phoenix,

So that was you filling up my error log and mailbox with the 404 File Not Found errors, eh? I was wondering who that was and what they were looking for.

The reason you couldn't find it is because it doesn't exist. It is something I did on my own.

That is done by almost duplicating the site_html_print_cat routine in site_html.pl except that the output goes to a file which is then imported to any page I want to display it on.

Since you indicated that you do not have subcategories, all you would need to do is create a few subroutines in site_html.pl or site_html_templates.pl and one in nph-build.cgi.

The first routine would be a duplicate of sub site_html_print_cat except that you would remove the code that splits it into two columns (look for the $half variable and the code that uses it to see what to delete). Since there are not subcategories, it would then give you a single column of your root categories, formatted however you wanted them to be. Once you have that code in place, you would put a command in nph-build.cgi to create a file that would contain the output from that routine. For example, I added this to nph-build.cgi for my routine:

Code:
sub build_cat_tree {
# --------------------------------------------------------
my ($subcat, @rootcat);
local ($total);

# Build a list of all available categories.
foreach $subcat (sort keys %category) {
if ($subcat !~ /^\s*$/) { push (@rootcat, $subcat);
}
}
print "Subcategories: "; print $#rootcat+1; print "\n";
print "Total Links: $grand_total\n";
print "\tOpening file: $db_script_path/data/cats.htm\n";
open (CATS, ">$db_script_path/data/cats.htm") or
&cgierr ("unable to open category tree file: $db_script_path/data/cats.htm\n. Reason: $!");
$category = &site_html_cat_tree (@rootcat) if ($#rootcat >= 0);
print CATS $category;
close CATS;
print "\tClosing file.\n";
}

The sub I wrote in site_html_templates.pl is called sub site_html_cat_tree. You can name it anything you want but be sure to change the "&site_html_cat_tree" in the code above to match it.

All that is left to do is create, in site_html.pl or site_html_templates.pl, the subroutine to read in the file created. In my script, it is thus:

Code:
sub get_allcats {
# --------------------------------------------------------
# This routine returns the category tree for display on the right
# side of tables used on home, new, cool, and category pages.

my $allcats;

open (CATS, "<$db_script_path/data/cats.htm")
or &cgierr("unable to open category tree file: $db_data_path/data/cats.htm. Reason: $!");
while (<CATS> )
{ $allcats .= $_; }
close CATS;

return $allcats;
}

At the top of site_html.pl or site_html_templates.pl in the Globals section, add something like this:

Code:
$allcats = &get_allcats;

If you are using templates, add to the %globals variable:

Code:
allcats => $allcats,

Now you are all set. Use $allcats in your site_html.pl routines whereever you need them or use <%allcats%> in your template files wherever you need them.

I hope this is clear. If you have any questions, feel free to ask.

[This message has been edited by Bobsie (edited March 17, 1999).]
Quote Reply
Re: Different Categories Question (v2) In reply to
Thanks so much, Bobsie. Very clear. For Pete's sake, copy it to a text file and post it to your site. :-) Yep, that was me with the zillion 404 errors, trying to figure out your naming convention and find the file. It it had been there, I'd have found it. :-)

Nother friendly suggestion... take all of your mod pages and add them as links in your Links database! I search for mods, and came up with nothing. All those great resources shouldn't be hidden.

Thanks again for the help.
Phoenix
Quote Reply
Re: Different Categories Question (v2) In reply to
For anyone else who may be interested in this mod, Bobsie left out one step. In nph-build.cgi under "sub build_all" you must also add something like the following:

# Make the Cat Tree
print "Building Category Tree . . .\n";
&build_cat_tree;
print "Done.\n\n";

Thank you again, Bobsie. Implemented and working just like I wanted.

Phoenix
Quote Reply
Re: Different Categories Question (v2) In reply to
Gee, did I really leave out that step? My goodness! Yes, do add that.

The reason I have not put that up on my site as a published mod is because I cannot seem to figure out how to do it with the staggered build. It has never worked in staggered build.
Quote Reply
Re: Different Categories Question (v2) In reply to
Bobsie,
What goes in the site_html for the subcategory layout?
Quote Reply
Re: Different Categories Question (v2) In reply to
Dan,

The layout is up to you based on your own individual tastes. I didn't include any code for sub site_html_cat_tree specifically for that reason. As I said, it is a duplicate of sub site_html_print_cat, but modified for how each person wants it to look. All the other code needed for site_html.pl or site_html_templates.pl are included in the previous message.
Quote Reply
Re: Different Categories Question (v2) In reply to
Bobsie,

When "Build All", I go this message:
---------------------------------------
Building Category Tree . . .
Subcategories: 36Total
Links: 15
Opening file: .../cgi bin/links/admin/data/cats.htm
Closing file.
-----------------------------------------
When I Checked the template for category listing that I added <%allcats%>, nothing is there. The "cats.htm" is good and I found all category listings are successfully built.

All my other index files(cool,rate,pick,etc...) are located in
-----------------------------------------
.../links/pages/
----------------------------------------

Am I on the right path?


Sitedex

[This message has been edited by sitedex (edited March 20, 1999).]
Quote Reply
Re: Different Categories Question (v2) In reply to
Sitedex,

Make sure that
allcats => &get_allcats
is listed in your globals in site_html_templates.pl, and then build all again... I've found (and I don't know why) that I have to build twice to make any changes to cats.htm show up on my pages. That could just be because I've got it doing things in the wrong order, but I haven't been able to fix it. So I build twice if I make category changes.
Phoenix
Quote Reply
Re: Different Categories Question (v2) In reply to
Phoenix,

It works now!
Thanks for your help

Sitedex
Quote Reply
Re: Different Categories Question (v2) In reply to
Phoenix,

Make sure this code is put in nph-build.cgi BEFORE any of the build pages calls:

Quote:
# Make the Cat Tree
print "Building Category Tree . . .\n";
&build_cat_tree;
print "Done.\n\n";

In my nph-build.cgi, I have it right after:

Quote:
# Generate some stats for future pages...
print "Gathering Category and Link information . . .\n";
&build_stats;
print "Done\n\n";

That should elminate the need to build twice.
Quote Reply
Re: Different Categories Question (v2) In reply to
Thanks, Bobsie.
That's actually right where I've got it. My build twice problem may be caused by one of the other mods I did myself before checking out the forum. Since I really don't know what I'm doing, the script is sort of jury-rigged together with twine and rubber cement. It's working, but probably not in the most glamorous possible way. Smile

Phoenix
Quote Reply
Re: Different Categories Question (v2) In reply to
I modified to the above message board but I still have to build twice to show correct number of links in category listing.

For example:
------------------------------------------
Computing (1)
------------------------------------------

but the correct count should be two links in Computing

------------------------------------------
Computing (2)
------------------------------------------

When I checked the "cats.htm" after the first "build", I found all categories and related number of links are updated correctly. In order for me to show the correct number of new links for each category , I have to build twice.


Sitedex

[This message has been edited by sitedex (edited March 21, 1999).]
Quote Reply
Re: Different Categories Question (v2) In reply to
sitedex (and phoenix),

Can you put your nph-build.cgi online as a text file and send me the url so I can look at it. Just email the url to me at the address below.


------------------
Bob Connors
bobsie@orphanage.com
www.orphanage.com/goodstuff/






[This message has been edited by Bobsie (edited March 21, 1999).]
Quote Reply
Re: Different Categories Question (v2) In reply to
Bobsie here is the nph_build.cgi:

Sorry!

[This message has been edited by sitedex (edited March 22, 1999).]
Quote Reply
Re: Different Categories Question (v2) In reply to
sitedex,

Now why did you post the entire script here? I asked you if you could put it online as a text file and provide me the URL specifically so it wouldn't take up so much bandwidth on the forum. If nothing else, you could have file attached it to the email you sent me.

Please edit that message and delete the script. I have it copied and will look it over. Let's save the people who pay by the minute for internet access some money! I'll post here if I find anything that may be causing your problem with the mod.
Quote Reply
Re: Different Categories Question (v2)<br> In reply to
Hello, found this and I wonder how this can be used with the yahoo 2.1 mod?

any suggestions?

Quote Reply
Re: [jdunes] Different Categories Question (v2)<br> In reply to
Hi Bobsie, I hope you don't mind me contact you via e-mail. My query regards forum:http://gossamer-threads.com/perl/gforum/gforum.cgi?do=ubb&ubb=000943:Forum3. In this post you supply details for listing categories, excluding subcats as the original user requested. I however do make use of subcats and would like to know if you could provide details for including subcats with this mod. Also I have noticed that none of the links to your site are working, is your site down ? Much appreciative Hamsterpants
Quote Reply
Re: [Hamsterpants] Different Categories Question (v2)<br> In reply to
I dunno if you will get a reply from Bobsie......he hasn't been on for over 1/2 a year Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Different Categories Question (v2)<br> In reply to
is there anyone else that could help with this?
Quote Reply
Re: [Hamsterpants] Different Categories Question (v2)<br> In reply to
i'll bite. what do you want to do with them?


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] Different Categories Question (v2)<br> In reply to
Hi Gene,



I found he post which Bobsie supplies the code to display categories (catree) on any pages as a list, but at the same time not affecting the original layout of the categories. In his notes he mentions that on his site he had subcat displayed aswell, but seeing as the user that requested the code only required to display the cats, he left out the code to display the subcats. I was therefore interested to find out if anyone had a copy of this.

Thanks
Hamsterpants
Quote Reply
Re: [Hamsterpants] Different Categories Question (v2)<br> In reply to
well, it depends on what you want to do. My categories are extremely stable so I don't know much about this. There is a hopto mod here in the forum and glennu did something similiar also.

If you just want them in a menu on each page and they don't change very often, just hard code them in the page. Or better yet, use the links include and/or ssi include to bring them into the page. that way all you have to do is change one file.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."