Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Show links in parent categories

Quote Reply
Show links in parent categories

Ive searched and searched, but didnt get anything worthwhile since I could not narrow down the search results.

Sorry if Im asking something thats already been answered. I do think Ive read something about this somewhere, but wasnt able to find it.

Under root I have say 4 main categories. Under each of those categories there are several subcategories.
I wish to show all links in those subcategories in the parent main category.

In my case there are 3 link levels. Each link displays randomly in order, but keeping always within its level.

Anyone have a global for doing this?


Juan Carlos
Quote Reply
Re: [Gorospe] Show links in parent categories In reply to

Mmm.. something like this should work (untested =))

Make a new global called "get_random_links_in_subs"

..with this code:

sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
#push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY RAND() DESC');

my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','Yes');
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;

my @cats;
while (my $hit = $sth->fetchrow_hashref) {

if ($CFG->{build_detailed}) { $hit->{detailed_url} = $CFG->{build_root_url} . "/" . $DB->table('Links')->detailed_url( $hit->{ID} ); }

if ($hit->{isNew} eq "Yes") { $hit->{isNew} = 1; } else { $hit->{isNew} = 0; }
if ($hit->{isPopular} eq "Yes") { $hit->{isPopular} = 1; } else { $hit->{isPopular} = 0; }
if ($hit->{isChanged} eq "Yes") { $hit->{isChanged} = 1; } else { $hit->{isChanged} = 0; }

push @cats, $hit;

return { links_in_this_cat => \@cats }


Then, call with:

<%loop links_in_this_cat%>
<%include link.html%>

.. in category.html

Hope that helps

Andy (mod)
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!