Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

List all categories and subcats

Quote Reply
List all categories and subcats
Is there a global that can allow me to show every category and every subcategory the site has, on one page? It would only show the name of each category/subcategory and the name would link to the category/subcategory page.

i.e
Travel
>Car
>Airplane
>Boat
>Hotel
Clothing
>J. Crew
>Gap
>Old Navy

etc.

Last edited by:

Gregorio: May 19, 2003, 11:24 AM
Quote Reply
Re: [Gregorio] List all categories and subcats In reply to
This is my site map code. You'll need to fiddle with it to get it looking how you want. It shows the first two levels of subcategories.

sub {
# -------------------------------------------------------------------
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name');
my $sth = $cat_db->select ( { FatherID => 0}, ['Full_Name','ID','Name'] );
my $output=qq~<table><tr valign=top><td width="25%"><table>~;
my $i=0;
while (my ($root_cat,$ID,$heading) = $sth->fetchrow_array) {
$i++;
my $url1 = $cat_db->as_url($root_cat);
$output.= qq~<tr><td colspan=2><font size=-1><b><a href="$CFG->{build_root_url}/$url1" class="toc">$heading</a></b></font></td></tr>~;
$cat_db->select_options ('ORDER BY Full_Name');
my $sth2 = $cat_db->select ( { FatherID => $ID}, ['Full_Name','ID','Name'] );
while (my ($cat,$id,$heading1) = $sth2->fetchrow_array) {
# my $link_count = $DB->table('CatLinks')->count ( {CategoryID => $id});
my $url = $cat_db->as_url($cat);
$output .= qq~<tr><td>&nbsp;</td><td><font size=-2><a href="$CFG->{build_root_url}/$url" class="toc">$heading1</a></font></td></tr>~;
$cat_db->select_options ('ORDER BY Full_Name');
my $sth3 = $cat_db->select ( { FatherID => $id}, ['Full_Name','ID','Name'] );
while (my ($cat2,$id2,$heading2) = $sth3->fetchrow_array) {
# my $link_count = $DB->table('CatLinks')->count ( {CategoryID => $id2});
my $url2 = $cat_db->as_url($cat2);
$output .= qq~<tr><td>&nbsp;</td><td><font size=-2>- <a href="$CFG->{build_root_url}/$url2" class="toc">$heading2</a></font></td></tr>~;
}
}
if (($i eq '13')or ($i eq '19') or ($i eq '33') or ($i eq '40')){ $output.=qq~</table></td><td width="25%"><table align=top>~;}
}
$output.="</table></td></tr></table>";
return $output;
}


Laura.
The UK High Street
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
AWESOME!! THAT WORKS GREAT!!

THANKS!!
Quote Reply
Re: [Gregorio] List all categories and subcats In reply to
Glad it worked.
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
Hello Laura,

I test the Global.

I use pagebuilder to publish information.

I obtain the URL following:

http://www.my_site/...page.cgi?page=father

My question:

It is possible to build a rewriting rule to obtain:

http://www.my_site.com/sitemap/

Thank you for your assistance

Mick
Quote Reply
Re: [mick31] List all categories and subcats In reply to
Hi Mick,

It is possible. Should be something like this:

RewriteRule ^/sitemap/$ /cgi-bin/directory/page.cgi?page=father [PT]

The PT might need changing to L or something else - this is just what works on my site.

Laura.
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
Laura

I test the rule but there is no change.

I do not find my error.

The rewriting rule is quite active on the waiter.

An idea?
I do not have experience on the subject!

The link should be modified ?
<a href="<%build_root_url%>/sitemap/">Sitemap</a>
Or
<a href="<%build_root_url%>/cgi-bin/directory/page.cgi?page=father">Sitemap</a>

Mick

Last edited by:

mick31: Nov 30, 2003, 7:44 AM
Quote Reply
Re: [mick31] List all categories and subcats In reply to
The link you should use is

<a href="<%build_root_url%>/sitemap/">Sitemap</a>

I'm not sure why it isn't working - are you using any other rewrite rules successfully?
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
Hello Laura

I have two file:

www
and
cgi-bin

I placed the .htaccess file in /cgi-bin/directory/ (page.cgi)

But, it seems that my waiter does not authorize the use of the rules in my file cgi-bin.

I use successfully the rules of Yogi (.htaccess file in www).

RewriteEngine On
RewriteRule ^.*N([0-9]+)/?$ /Detailed/$1.htm [L]

Mick
Quote Reply
Re: [mick31] List all categories and subcats In reply to
Try just adding the new rule below the existing one (I'm not quite sure how .htaccess files work as all my rules are within the httpd.conf file).
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
Personally I use rules in .htaccess. The rules in .htaccess files work same way as rules within the httpd.conf file, except, that rules in .htaccess files are somewhat slower than in httpd.conf, and some directives are not available in .htaccess. However if you don't own the webserver, you can not place rules into httpd.conf file.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
Is it easy to modify this code to show all sub-categoires? I haven't tried yet but was just wondering if someone has already did it.

Thanks,

Craven
Quote Reply
Re: [craven32] List all categories and subcats In reply to
What about this (untested):

sub {
# -------------------------------------------------------------------
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name');
my $sth = $cat_db->select (['Full_Name','ID','Name'] );
my $output=qq~<table><tr valign=top><td width="25%"><table>~;
my $i=0;
while (my ($cat,$ID,$heading) = $sth->fetchrow_array) {
$i++;
my $url1 = $cat_db->as_url($cat);
$output.= qq~<tr><td><font size=-1>~;
my $depth = ($cat =~ tr/\///);
if ($depth > 0){$output .= "&nbsp;&nbsp;"x$depth;}
$output.=qq~<b><a href="$CFG->{build_root_url}/$url1" class="toc">$heading</a></b></font></td></tr>~;
if (($i eq '13')or ($i eq '19') or ($i eq '33') or ($i eq '40')){ $output.=qq~</table></td><td width="25%"><table align=top>~;}
}
$output.="</table></td></tr></table>";
return $output;
}
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
That works perfectly. Thanks

What part of the code do I need to modify to change the layout of the page? And the size of the subcats?

Thanks,

Craven
Quote Reply
Re: [craven32] List all categories and subcats In reply to
All the html is in the variable $output so you'll just need to play around with all those bits to get it looking how you want. You'll probably need to change all the numbers in the line

if (($i eq '13')or ($i eq '19') or ($i eq '33') or ($i eq '40')){ $output.=qq~</table></td><td width="25%"><table align=top>~;}

The 13,19,33 and 40 are just the numbers that I used when I wrote the global - this says make a new column after the 13th category, etc.

You can change the size by changing the <font size=-1> (or removing it).
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
I've been playing around with this global but can't seem to figure out what I need to change to make the Root categories be bold and have a larger font than the sub-cats.

Any suggestions on this?

Thanks,

Craven
Quote Reply
Re: [craven32] List all categories and subcats In reply to
Try this - match the green html for the subcategories and match the red html for the root categories.

sub {
# -------------------------------------------------------------------
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name');
my $sth = $cat_db->select (['Full_Name','ID','Name'] );
my $output=qq~<table><tr valign=top><td width="25%"><table>~;
my $i=0;
while (my ($cat,$ID,$heading) = $sth->fetchrow_array) {
$i++;
my $url1 = $cat_db->as_url($cat);
$output.= qq~<tr><td>~;
my $depth = ($cat =~ tr/\///);
if ($depth > 0){$output .= "&nbsp;&nbsp;"x$depth."<font size=-1>";}
else {$output.="<b>";}
$output.=qq~<a href="$CFG->{build_root_url}/$url1" class="toc">$heading</a>~;
if ($depth > 0){$output .= "</font>";}
else {$output.="</b>";}
$output.=qq~</td></tr>~;
if (($i eq '13')or ($i eq '19') or ($i eq '33') or ($i eq '40')){ $output.=qq~</table></td><td width="25%"><table align=top>~;}
}
$output.="</table></td></tr></table>";
return $output;
}
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
Hi Thanks for the fast reply! For some reason I keep getting an "Unable to compile 'site_map'" error when using this global. I've changed a few things around but I'm not sure where the problems is.

Craven
Quote Reply
Re: [craven32] List all categories and subcats In reply to
Maybe I'm missing something obvious but I can't see what the problem would be. Do you want to pm me the exact global you're using and I'll see whether I can spot the problem?

Laura.
The UK High Street
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
Afinir,

would it be possible to exclude a top category from this globals html output?


thank you for your time. Smile
Quote Reply
Re: [nt6] List all categories and subcats In reply to
Yes, you can just add a condition statement before the select:

my $cond = GT::SQL::Condition->new( 'Full_Name', 'LIKE', 'category%');
$cond->not;
my $sth = $cat_db->select (['Full_Name','ID','Name'],$cond);

(obviously you need to replace category with the name of the root category that you want to leave out)

or you could put some code inside the while loop so that the category doesn't get added to the output.
Quote Reply
Re: [afinlr] List all categories and subcats In reply to
wow, worked fine. Thanks a bunch!Smile