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

Re: [nir] related categories links

Quote Reply
Re: [nir] related categories links In reply to
Ok, took a while to get right (I thought we could just get a list of values as an arrayref direct from $DB, but seems we can't - so had to do it a more long winded way.

Anyhow, this should work:

get_links_from_related_cats
Code:
sub {

my $cat_id = $_[0];

my $sth = $DB->table("CatRelations")->select( ['RelatedID'], { CategoryID => $cat_id } );
my $cats;
while (my $hit = $sth->fetchrow_hashref) {
push @$cats, "$hit->{RelatedID}";
}

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ("ORDER BY " .$CFG->{build_sort_order_category});

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

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

if ($CFG->{build_detailed}) { $hit->{detailed_url} = $CFG->{build_detail_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 @loop, $hit;

}

return { related_cat_links => \@loop }

}


Code:
<%get_links_from_related_cats($ID)%>
<%if related_cat_links.length%>
<%loop related_cat_links%>
<%include link.html%>
<%endloop%>
<%endif%>

Obviously this will only work in category.html.

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!
Subject Author Views Date
Thread related categories links nir 23257 Aug 4, 2009, 3:30 AM
Thread Re: [nir] related categories links
Andy 22971 Aug 4, 2009, 3:51 AM
Thread Re: [Andy] related categories links
nir 22891 Aug 4, 2009, 4:23 AM
Thread Re: [nir] related categories links
Andy 22876 Aug 4, 2009, 8:46 AM
Thread Re: [Andy] related categories links
nir 22864 Aug 5, 2009, 1:08 AM
Thread Re: [nir] related categories links
Andy 22861 Aug 5, 2009, 1:52 AM
Thread Re: [Andy] related categories links
nir 22897 Aug 5, 2009, 2:03 AM
Thread Re: [nir] related categories links
Andy 22843 Aug 5, 2009, 2:09 AM
Thread Re: [Andy] related categories links
nir 22846 Aug 5, 2009, 2:16 AM
Thread Re: [nir] related categories links
Andy 22853 Aug 5, 2009, 2:43 AM
Thread Re: [Andy] related categories links
nir 22854 Aug 5, 2009, 5:04 AM
Thread Re: [nir] related categories links
Andy 22905 Aug 5, 2009, 5:12 AM
Thread Re: [Andy] related categories links
nir 22842 Aug 5, 2009, 5:15 AM
Thread Re: [nir] related categories links
Andy 22823 Aug 5, 2009, 5:19 AM
Post Re: [Andy] related categories links
nir 22781 Aug 5, 2009, 5:24 AM
Thread Re: [Andy] related categories links
socrates 19950 Feb 27, 2017, 3:41 PM
Thread Re: [socrates] related categories links
Andy 19933 Feb 28, 2017, 12:40 AM
Thread Re: [Andy] related categories links
socrates 19891 Feb 28, 2017, 8:00 PM
Thread Re: [socrates] related categories links
Andy 19872 Feb 28, 2017, 10:32 PM
Thread Re: [Andy] related categories links
socrates 19863 Mar 1, 2017, 1:31 AM
Thread Re: [socrates] related categories links
Andy 19834 Mar 1, 2017, 2:20 AM
Thread Re: [Andy] related categories links
socrates 19808 Mar 2, 2017, 3:39 AM
Thread Re: [socrates] related categories links
Andy 19781 Mar 2, 2017, 3:50 AM
Thread Re: [Andy] related categories links
socrates 19793 Mar 2, 2017, 4:33 AM
Post Re: [socrates] related categories links
Andy 19740 Mar 2, 2017, 6:18 AM