Gossamer Forum
Home : Products : Gossamer Links : Discussions :

ULTRAGlobals question

Quote Reply
ULTRAGlobals question
Hello.
I'm using UltraGlobals to show random links of a category on the category page:

# Random_Links

<%Plugins::ULTRAGlobals::Random_Links(LIMIT,'category_id')%>

Example:

<%Plugins::ULTRAGlobals::Random_Links(10,$ID)%>
<%if Random_Loop.length%>
<%loop Random_Loop%>
<%include link.html%>
<%endloop%>
<%endif%>

Now my question: Is it possible to show links from all child-categories of the with $ID selected category?
Currently it shows only the links from the with $ID selected category.

Knubbel

Last edited by:

Knubbel: Aug 7, 2008, 1:59 AM
Quote Reply
Re: [Knubbel] ULTRAGlobals question In reply to
Hi,

Untested, but you could try a new global:

random_links_by_category
Code:
sub {

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

my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isValidated','=','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_root_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 { rand_links_in_this_cat => \@cats }

}

..then call with:

Code:
<%random_links_by_category($ID,10)%>
<%if rand_links_in_this_cat.length%>
<%loop rand_links_in_this_cat%>
<%include link.html%>
<%endloop%>
<%endif%>

Untested, but should work fine =)

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!

Last edited by:

Andy: Aug 7, 2008, 2:15 AM
Quote Reply
Re: [Andy] ULTRAGlobals question In reply to
It runs very, very great.

But it shows only 5.

Must I change this line?:

$db_obj->select_options ('ORDER BY RAND() DESC Limit 5');


Knubbel

Quote Reply
Re: [Knubbel] ULTRAGlobals question In reply to
Sorry, forgot to change that bit =) Please try the modified version above.

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] ULTRAGlobals question In reply to
Thanks, it works great!

Knubbel