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

links_loop inside category_loop

Quote Reply
links_loop inside category_loop
I am trying to trim some of our lower level category pages and we would like to have pages where all the links under subcategory pages will show under parent category page grouped by subcategories.

Now we have Category page and Subcategory pages like:

CATEGORY PAGE

SubCategory1 Name
SubCategory2 Name
SubcategoryN Name

SUBCATEGERY1 PAGE
Link1
Link2
Link3

SUBCATEGERY2 PAGE
Link5
Link6
Link10

SUBCATEGERY_N PAGE
LinkN
LinkM

but we would like to have only CATEGORY page like:

CATEGORY PAGE

SubCategory1 Name
Link1
Link2
Link3
SubCategory2 Name
Link5
Link6
Link10
.....
SubCategoryN Name
LinkN
LinkM

I tried to run links loop inside category loop but apparently it doesn't work like that.
Can anybody help to achieve our desired outcome?
Thanks!

Last edited by:

AMIXIMA: May 28, 2012, 8:26 AM
Quote Reply
Re: [AMIXIMA] links_loop inside category_loop In reply to
Hi,

Are you saying you want to do a loop of <%category_loop%>, and inside that , then loop the links for that category? If so, you could do it with a new global:

get_cat_links
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 Title DESC LIMIT 20');

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) {
$link = Links::SiteHTML::tags('link', $link);
push @cats, $hit;
}

return { link_sub_loop => \@cats }

}

Then call something like:
Code:
<%loop category_loop%>
<%include subcategory.html%>
<%get_cat_links ($ID)%>
<%if link_sub_loop.length%>
<%loop link_sub_loop.length%>
<%include link.html%>
<%endloop%>
<%endif%>

Untested, but it should work Smile

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 (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] links_loop inside category_loop In reply to
Hi Andy,

Thank so much for your quick solution!

There were two small omissions in your code, I fixed those and it works perfectly.
1. in Global code you need to add "my $link;" at the beginning of the code.
2. Instead of <%loop link_sub_loop.length%> should be <%loop link_sub_loop%>



Quote Reply
Re: [AMIXIMA] links_loop inside category_loop In reply to
Ah yeah - thats what happenes when you try and reply when in a rush hehe Angelic Glad it helped though

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 (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