Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Display all Links

Quote Reply
Display all Links
I have been experimenting with several parts of the script but I'm not as skilled in Perl as I would like to think. My goal is to get all my subcategory links for a specific category to display on the same page.

Say I have the following main category: "Cars"
And the main category Cars has several subcategories like "Foreign" and "Domestic"

How can I set it up so people who click on the "Cars" category from the home page will be shown a page that has all the links from both subcategories on it? Additionally I would like for the "Domestic" links to be listed before the "Foreign" links?


Thank You,

-Z
Quote Reply
Re: [Zandilion] Display all Links In reply to
Try;

<%load_lower_links($ID)%>

($ID **MUST** be the category ID, and not a link ID)

Code:
sub {

my $catID = $_[0];
my $catname = $DB->table('Category')->select( ['Full_Name'], { ID => $catID } )->fetchrow;

my $sth = $DB->table('Category')->select( GT::SQL::Condition->new('Full_Name','LIKE',"$catname/%") ) || die $GT::SQL::error;

my @links;
while (my $hit = $sth->fetchrow_hashref) {
my $links_sth = $DB->table('CatLinks')->select( { CategoryID =>$hit->{ID} } ) || die $GT::SQL::error;
while (my $hit2 = $links_sth->fetchrow_hashref) {
my $hit3 = $DB->table('Links')->get($hit2->{LinkID});
push @links, $hit3;
}
}
return { loop_all_links => \@links };
}

Then call the loops with;

Code:
<%if loop_all_links%>
<%loop loop_all_links%>
<%include link.html%><BR>
<%endif%>
<%endif%>

This is untested, but should work :)

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 | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Display all Links In reply to
I found your reply to this post very useful. This forum is fortunate to have frequent replies like yours submitted.

The global code worked fine but I had couldn't get the template code to output anything.

Note: x is a hardcoded category ID which I passed as a test.
Code:
<%load_lower_links(x)%>

<%if loop_all_links%>
<%loop loop_all_links%>
<%include link.html%><BR>
<%endif%>
<%endif%>



I modified the global to just return the html output of the list of links and that appeared to work fine. I also added an OR condition to grab the links directly under that category in addition to the links under all subcategories which is what you had.

<%load_lower_links($ID)%>

Code:
sub {
require Links::SiteHTML;
my $catID = $_[0];
my $catname = $DB->table('Category')->select( ['Full_Name'], { ID => $catID } )->fetchrow;
my $cond = GT::SQL::Condition->new(
Full_Name => '=' => "$catname",
Full_Name => 'LIKE' => "$catname/%"
);
$cond->bool('OR');
my $sth = $DB->table('Category')->select( $cond ) || die $GT::SQL::error;
my $output;
while (my $hit = $sth->fetchrow_hashref) {
my $links_sth = $DB->table('CatLinks')->select( { CategoryID =>$hit->{ID} } ) || die $GT::SQL::error;
while (my $hit2 = $links_sth->fetchrow_hashref) {
my $hit3 = $DB->table('Links')->get($hit2->{LinkID});
$output .= Links::SiteHTML::display('link', $hit3);
}
}
return $output;
}


Cheers,

Regards,
Peter Puglisi
www.ausfreedom.com
Ultimate Freedom is our game.
Quote Reply
Re: [rocco] Display all Links In reply to
Hi,

No problem :)

It should work with that template code. I would recommend how to debug it... but if you're not intending on using it like that, then it would be a waste of time typing <G>

Glad it worked 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 | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [rocco] Display all Links In reply to
Hi

Any idea how to sort the output alphabetically...
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Display all Links In reply to
Try changing;

Code:
my $sth = $DB->table('Category')->select( $cond ) || die $GT::SQL::error;

...to;

Code:
my $cat_tbl = $DB->table('Category');
$cat_tbl->select_options('ORDER BY Full_Name DESC');
my $sth = $cat_tbl->select( $cond ) || die $GT::SQL::error;

Andy (mod)
andy@ultranerds.co.uk
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!
Quote Reply
Re: [Andy] Display all Links In reply to
Thanks Andy

BUT that is not sorting the links alphabetically..

I think that is meant to sort the category names.
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Display all Links In reply to
I have been thinking of implementing something like this...GLAD I found this thread.

I'm wondering if any of the gurus out there can recommend as to whether using a method like this would be an unusual drain on server resources or an inefficient way to display listings from a categories sub categories?

Thanks in advance,
mike