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

[Is this possible?] : Include Random Links that with certain link-properties?

Quote Reply
[Is this possible?] : Include Random Links that with certain link-properties?
Using UltraGlobal's 'Random_Link_In_Category' code is it possible to display All Links in a certain category (& its sub-category) that have a certain link property?

------------------------------------------
<%Plugins::ULTRAGlobals::Random_Link_In_Category($ID,'7')%>

<%if random_link_in_this_cat.length%>
<%loop random_link_in_this_cat%>
<%include link.html%>
<%endloop%>
<%endif%>
------------------------------------------
I am considering adding a link-property field (example: 'is_partner', with value as Yes/No)

& on every category page, I want to display all is_partner (set to 'Yes') links in the left bar or footer (still finalizing on design).

Is it possible to do this using the above global or some other global?

1. Generally most main/root categories will have 2000+ links.
2. Also, if there are only 4 links set as is_partner, then I only want the global to say 4.
3. Ideally, I would want the link order/sorting to be randomized with every page reload.


Thank you.

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] [Is this possible?] : Include Random Links that with certain link-properties? In reply to
load_random_partners_in_cat

Code:
sub Random_Link_In_Category {

my $cat = $_[0];
my $limit = $_[1] || ;
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 RAND() LIMIT $limit");

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

my @cats;
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 @cats, $hit;
}

return { random_partner_link_in_this_cat => \@cats }

}

Code:
<%load_random_partners_in_cat($ID,4)%>
<%if random_partner_link_in_this_cat.length%>
<%loop random_partner_link_in_this_cat%>
<%include link.html%>
<%endloop%>
<%endif%>

Something like that should work. That will get matches from ANY sub-category as well. If you only want it to find links in the actual category ID you are looking at, then something like this:

Code:
sub Random_Link_In_Category {

my $cat = $_[0];
my $limit = $_[1] || 1;

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

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

my @cats;
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 @cats, $hit;
}

return { random_partner_link_in_this_cat => \@cats }

}

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] [Is this possible?] : Include Random Links that with certain link-properties? In reply to
Thank you Andy, This is awesome, appreciate your help..

Thanks again :)

Vishal
-------------------------------------------------------