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

Main Category / Sub Category Global

Quote Reply
Main Category / Sub Category Global
I've got a global that I'm happy with but I want to remove all the subcategories so that it just shows the main categories...

Any ideas? Thanks for any help in advance...

Code:
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','CatDepth','Number_of_Links','Has_New_Links','Has_Changed_Links'] );
my $output=qq~<table width="100%"><tr valign=top><td width="50%"><table>~;
my $i=0;
while (my ($cat,$ID,$heading,$depth,$cnt,$new,$changed) = $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> ($cnt)~;
if ($new eq "Yes") { $output .= qq| <span class="new-item"><span>new</span></span> |; }
if ($changed eq "Yes") { $output .= qq| <span class="updated-item"><span>updated</span></span> |; }
if ($depth > 0){
$output .= "</font>";
} else {$output.="</b>";}
$output.=qq~</td></tr>~;
if (($i eq '38')){ $output.=qq~</table></td><td width="50%"><table align=top>~;}
}
$output.="</table></td></tr></table>";
return $output;
}
Quote Reply
Re: [markhe] Main Category / Sub Category Global In reply to
If I am not wrong, CatDepth and FatherID for all Main Categories is '0'. Dont know how to use that in global, however I think if you set condition in cat_db-> select, then it might work???

Its just a guess, I am certain someone more knowledgeable will be able to make it more clear.

Vishal

-------------------------------------------------------
Web Hosting Kit: A to Z of Web Hosting! http://www.webhostingkit.com/
Software Devil: Software Search Made Easy! http://www.softwaredevil.com/
-------------------------------------------------------
Quote Reply
Re: [SWDevil.Com] Main Category / Sub Category Global In reply to
Hi I'm using this global, to show my top categories. Works fine for me

Code:
sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options ("ORDER BY priority");
my $sth = $cat_db->select (['Full_Name'], { FatherID => 0 });
my $output;
while ( my $root_cat = $sth->fetchrow_array) {
my $url = $cat_db->as_url($root_cat);
$output .= qq~<li><a href="$CFG->{build_root_url}/$url">$root_cat</a></li>~;
}
return $output;
}


Perhaps you just have to use the { FatherID => 0 } this way
Matthias

Matthias
gpaed.de

Last edited by:

Matthias70: Aug 16, 2007, 1:31 AM
Quote Reply
Re: [markhe] Main Category / Sub Category Global In reply to
Hi,

Just change:

Code:
my $sth = $cat_db->select (['Full_Name','ID','Name','CatDepth','Number_of_Links','Has_New_Links','Has_Changed_Links'] );

...to:

Code:
my $sth = $cat_db->select (['Full_Name','ID','Name','CatDepth','Number_of_Links','Has_New_Links','Has_Changed_Links'], { FatherID => '0' } );

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates

Last edited by:

Andy: Aug 16, 2007, 1:47 AM
Quote Reply
Re: [Andy] Main Category / Sub Category Global In reply to
Thanks for the help. Used Andy's and works great , one further enhancement if possible.... Can I force it to show two columns?
Quote Reply
Re: [markhe] Main Category / Sub Category Global In reply to
Hi,

haha - you don't ask for much Tongue

Try this:

Code:
sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options ("ORDER BY priority");
my $sth = $cat_db->select (['Full_Name'], { FatherID => 0 });
my $output = qq|<table>|;
my $cnt = 1;

while ( my $root_cat = $sth->fetchrow_array) {
my $url = $cat_db->as_url($root_cat);
if ($cnt == 1) {
$output .= qq~<tr><td><a href="$CFG->{build_root_url}/$url">$root_cat</a></td>~;
$cnt = 2;
} elsif ($cnt == 2) {
$output .= qq~<td><a href="$CFG->{build_root_url}/$url">$root_cat</a></td></tr>~;
$cnt = 1;
}
}

if ($output =~ /<\/td>$/) {
$output .= qq~<td></td></tr>~;
}

$output .= qq|<table>|;

return $output;

}

You may wanna edit the <table> bit, so it has your desired width="" etc paramaters.

Its all tested on my dev install, and works a charm =)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Main Category / Sub Category Global In reply to
Thanks again Andy but for some reason, if I use this code... it just shows "maintenance" and a white page.

I tried a few "tweaks" swapping code from old and new but sadly, I am just not understanding the global language..lol

Mark
Quote Reply
Re: [markhe] Main Category / Sub Category Global In reply to
Hi,

Do you have an example URL?

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates