Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How to display root categroies in "new", "cool" and "top" pages?

Quote Reply
How to display root categroies in "new", "cool" and "top" pages?
Hi,



the <%category%> tag does not work outside of a proper category.

What do I need to do to display all the root categories in other pages like "new", "cool" and "top"?



Thank you for your time.
Quote Reply
Re: [nt6] How to display root categroies in "new", "cool" and "top" pages? In reply to
You need a global.

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'] );
my $output="";
while (my ($root_cat) = $sth->fetchrow_array) {
my $url = $cat_db->as_url($root_cat);
$output .= qq~<a href="$CFG->{build_root_url}/$url"><b>$root_cat</b></a><br>~;
}
return $output;
}

Haven't checked this but its something like that. Change the $output variable to however you want it output.
Quote Reply
Re: [afinlr] How to display root categroies in "new", "cool" and "top" pages? In reply to
Thank you for the global. It works fine.

What would I need to do to get it to display the root categories using the default "subcategory" template?
Quote Reply
Re: [nt6] How to display root categroies in "new", "cool" and "top" pages? In reply to
Change the output line to

$output .= Links::SiteHTML::display ('subcategory', $rootcat);

Think you will also need to remove the ['Full_name'] from the $sth line as I think that it needs more info than this in the subcategory template. And the $url variable will no longer be needed.

Laura.
Quote Reply
Re: [nt6] How to display root categroies in "new", "cool" and "top" pages? In reply to
test
Quote Reply
Re: [afinlr] How to display root categroies in "new", "cool" and "top" pages? In reply to
Hi,



Thank you but the global doesn't work.

I get this error message:

Global symbol "$rootcat" requires explicit package name at (eval 14)

With this global:

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});
my $output="";
while (my ($root_cat) = $sth->fetchrow_array) {
$output .= Links::SiteHTML::display ('subcategory', $rootcat);
}
return $output;
}



Any ideas?
Quote Reply
Re: [nt6] How to display root categroies in "new", "cool" and "top" pages? In reply to
Sorry, should be root_cat not rootcat!

Laura.
Quote Reply
Re: [afinlr] How to display root categroies in "new", "cool" and "top" pages? In reply to
Thank you for your reply Laura : )



Now I get this error message:



Can't use string ("40") as a HASH ref while "strict refs"

Any Ideas?
Quote Reply
Re: [nt6] How to display root categroies in "new", "cool" and "top" pages? In reply to
Change:

while (my ($root_cat) = $sth->fetchrow_array) {

to

while (my ($root_cat) = $sth->fetchrow_hashref) {
Quote Reply
Re: [Paul] How to display root categroies in "new", "cool" and "top" pages? In reply to
Paul & Laura,

Here is the global I am using:



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});
my $output="";
while (my ($root_cat) = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('subcategory', $root_cat);
}
return $output;
}

I am not getting any error messages, but my "New" page will not come up in the browser. When I call it the page never stops loading, so it never comes up on screen.



I hope you have some idea?

Thank you for your time.
Quote Reply
Re: [nt6] How to display root categroies in "new", "cool" and "top" pages? In reply to
Sorry, hadn't tried this when I replied but this should work:

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 } );

my $output="";
my $root = [{}];
while (my $root_cat = $sth->fetchrow_hashref) {
push @$root, $root_cat;
}
$output = Links::SiteHTML::display ('print_cat', $root);
return $output;
}
Quote Reply
Re: [afinlr] How to display root categroies in "new", "cool" and "top" pages? In reply to
You'll probably want:

my $root = [];

not:

my $root = [{}];
Quote Reply
Re: [Paul] How to display root categroies in "new", "cool" and "top" pages? In reply to
Wow, this is a nice little global. Thanks to both of you.

What would it take to make this global display in the GT forum "categoy_list.html" template?
Quote Reply
Re: [afinlr] How to display root categroies in "new", "cool" and "top" pages? In reply to
Great global. It is just what I was looking for. But the deisplay of the links is pretty large. Is there a way to format the html for this? Changing font size in particluar.

thanks
CCUnet
my Christian web
Quote Reply
Re: [ccunet] How to display root categroies in "new", "cool" and "top" pages? In reply to
You should just be able to change this line to the format that you want:
$output .= qq~<a href="$CFG->{build_root_url}/$url"><b>$root_cat</b></a><br>~;
Quote Reply
Re: [afinlr] How to display root categroies in "new", "cool" and "top" pages? In reply to
Thanks Laura,
I did solve it by using a ccs style in the template where I call the global.
But for my further education acould you tell me whathte diffrence is bewteen these two output statements
Code:

$output = Links::SiteHTML::display ('print_cat', $root);
and




$output .= qq~<a href="$CFG->{build_root_url}/$url"><b>$root_cat</b></a><br>~;
my Christian web
Quote Reply
Re: [ccunet] How to display root categroies in "new", "cool" and "top" pages? In reply to
Hi,

The first one just says print the 'print_cat' template using the values of the hashref $root for the tags.
The second one is the samething but what would be in 'print_cat' is hardcoded into the global.

Which you choose is a matter of preference - if you use the same output from lots of different globals it is easier to use a template so that you can make one change to change the output from them all. However, if you have lots of globals with lots of different outputs, you may find it easier to hardcode the output otherwise you'll have hundreds of extra tiny templates.