Gossamer Forum
Quote Reply
FatherID with Global
 
How do I get the FatherID instead of ID with this global?


Code:
sub {
# return random related links
my (@links,$sth,$link);
my $tags = shift;
my ($cat_id) = each %{$DB->table('Links')->get_categories($tags->{ID})};
my $link_db = $DB->table('Links','CatLinks','Category');
$link_db->select_options ("ORDER BY RAND()","LIMIT 6");
my $sth = $link_db->select ( { CategoryID => $cat_id }, {isValidated => 'Yes'});
while (my $link = $sth->fetchrow_hashref) {
$link = Links::SiteHTML::tags('link', $link);
unless ($link->{ID} == $tags->{ID}){
push@links, $link;
}
}
return {relatedlnks=>\@links};
}


Code:
sub {
# return random related links
my (@links,$sth,$link);
my $tags = shift;
my ($cat_id) = each %{$DB->table('Links')->get_categories($tags->{ID})};
my $link_db = $DB->table('Links','CatLinks','Category');
$link_db->select_options ("ORDER BY RAND()","LIMIT 6");
my $sth = $link_db->select ( { FatherID => $cat_id }, {isValidated => 'Yes'});
while (my $link = $sth->fetchrow_hashref) {
$link = Links::SiteHTML::tags('link', $link);
unless ($link->{ID} == $tags->{ID}){
push@links, $link;
}
}
return {relatedlnks=>\@links};
}

~ ERASER


Free JavaScripts @ Insight Eye

Last edited by:

Eraser: Aug 2, 2008, 6:32 AM
Quote Reply
Re: [Eraser] FatherID with Global In reply to
Hi,

Not sure what you mean - what are you trying to achive?

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] FatherID with Global In reply to
Well, currently the global shows random links from the same category as the link ID the global is called from - such as the detailed page.

So when the global looks up the linkid to get category info, I'm trying to get the FatherID as well.

This way, the global will not just show links in the current cat, but from the cats with the fatherId returned.

Little hard to explain - but hope that makes sense!

~ ERASER


Free JavaScripts @ Insight Eye

Last edited by:

Eraser: Aug 2, 2008, 8:15 AM
Quote Reply
Re: [Eraser] FatherID with Global In reply to
Hi,

Mmm... satill not really sure what your trying to do =)

Are you trying to do something like:

gloabal($ID) (where $ID is the linkID)

...then that gets the category ID that link is in - and then gets a random selection of 6 links, from the current category (and its sub-categories)

Is that right?

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] FatherID with Global In reply to
Hi Andy,

almost -

"then that gets the category ID that link is in - and then gets a random selection of 6 links, from the current category (and its sub-categories) "

expect I need the category up one, then all its subcategories including the current category.

So:
/Cars/Ford/Escort/detaled_page

The first global get links from Escort, not Ford as needed.

~ ERASER


Free JavaScripts @ Insight Eye
Quote Reply
Re: [Eraser] FatherID with Global In reply to
Hi,

This is TOTALLY untested:

get_rand_from_top_cat
Code:
sub {

my $current_cat_id = $DB->table('CatLinks')->select( ['CategoryID'], { LinkID > $_[0] } )->fetchrow;
my $cat_name = $DB->table('Category')->select( ['Full_Name'], { ID => $current_cat_id } )->fetchrow;

my @tmp = split /\//, $cat_name;
pop @tmp;

my $higher_up_cat = $DB->table('Category')->select( ['ID'], { Full_Name => join('/',@tmp) } )->fetchrow;

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

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

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

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

return { relatedlinks => \@links };
}

..call with:

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

Just be sure you don't just overwrite your old global from the template, in case its not what you want (I'm gonna call it a day in a min, as its gone 8pm ;))

Best bet, is to set it up - just in the footer of detailed.html, so you can see what it looks like / if it works =)

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] FatherID with Global In reply to
Many thanks for this code, Andy. I will try this and adjust if necessary.

Thanks again!

~ ERASER


Free JavaScripts @ Insight Eye