Gossamer Forum
Quote Reply
related categories links
How I can get list in a category of all related links, I mean the category have some Related category and I need the link of the Related categories.
Quote Reply
Re: [nir] related categories links In reply to
You mean you want to get the related categories, and then "grab" the links that are in that category, and show them on category.html too?

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
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] related categories links In reply to
Yes,
To show the links that are in the related categories in the category.html.
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


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
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] related categories links In reply to
Thanks it workSmile, and Thanks again
Can you show me how I can get the list on the related categories with a loop so I can control its look.
Quote Reply
Re: [nir] related categories links In reply to
Glad it worked. To get a list of the categories that are related to the current category, you would do something like (untested)

work_out_related_cats
Code:
sub {
my $cat_id = $_[0];

my $sth = $DB->table("CatRelations")->select( { CategoryID => $cat_id } );
my @related_cats;
while (my $hit = $sth->fetchrow_hashref) {
my $cat = $DB->table('Category')->select( { ID => $hit->{RelationID} } )->fetchrow_hashref;
$cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $cat->{Full_Name} ) . "/" . $CFG->{build_index};
if (length $hit->{RelationName} > 0) {
$cat->{Name} = $hit->{RelationName};
}
push @related_cats, $cat;
}

return { related_cat_loop => \@related_cats };
}

Then in category.html:

Code:
<%work_out_related_cats($ID)%>
<%if related_cat_loop.length%>
<%loop related_cat_loop%>
<a href="<%URL%>"><%Name%></a> <br />
<%endloop%>
<%endif%>

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
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

Last edited by:

Andy: Aug 5, 2009, 2:43 AM
Quote Reply
Re: [Andy] related categories links In reply to
The results return the name and ID of the current category, I try to change it to RelationName and RelatedID but it didn’t know this value.
Quote Reply
Re: [nir] related categories links In reply to
Sorry, my mistake - please try the edited versions above (I made a few mess ups in the last version =))

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
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] related categories links In reply to
It return the correct name but it does not return the correct URL , the URL have no ID
Quote Reply
Re: [nir] related categories links In reply to
Oops, please change:

Code:
$cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $hit->{Full_Name} ) . "/" . $CFG->{build_index};

to

Code:
$cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $cat->{Full_Name} ) . "/" . $CFG->{build_index};

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
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] related categories links In reply to
It give for all the link //index.html without the ID
Quote Reply
Re: [nir] related categories links In reply to
What do you see when you put:

<%DUMP related_cat_loop%>

?

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
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] related categories links In reply to
Dumped value of 'related_cat_loop':
[
{
'Name' => 'aaa',
'URL' => '//index.html'
},
{
'Name' => 'sss',
'URL' => '//index.html'
},
{
'Name' => 'ddd',
'URL' => '//index.html'
}
];
Quote Reply
Re: [nir] related categories links In reply to
Ah, I see the problem - try this:

Code:
sub {
my $cat_id = $_[0];

my $sth = $DB->table("CatRelations")->select( { CategoryID => $cat_id } );
my @related_cats;
while (my $hit = $sth->fetchrow_hashref) {
my $cat = $DB->table('Category')->select( { ID => $hit->{RelatedID} } )->fetchrow_hashref;
$cat->{URL} = $CFG->{build_root_url} . "/" . $DB->table('Category')->as_url( $cat->{Full_Name} ) . "/" . $CFG->{build_index};
if (length $hit->{RelationName} > 0) {
$cat->{Name} = $hit->{RelationName};
}
push @related_cats, $cat;
}

return { related_cat_loop => \@related_cats };
}

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
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] related categories links In reply to
Its workSmile, thanks for your time and help