This is untested:
sub {
# Displays the sponsored links on every page.
my ($output,$sth,$link,$cond);
my $tags=shift;
my $catid = $tags->{catid};
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY rand()");
if ($catid){
my $cat_db = $DB->table('Category');
my $all_ids = $cat_db->children($cat_id);
push @$all_ids, $cat_id;
$cond = GT::SQL::Condition->new('sponsors', '=', 'Yes', 'isValidated','=','Yes', 'CategoryID', 'IN', $all_ids);
}
else {
$cond = GT::SQL::Condition->new('sponsors', '=', 'Yes', 'isValidated','=','Yes');
}
$sth = $search_db->select ($cond);
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link_sponsored', $link);
}
return $output;
}
sub {
# Displays the sponsored links on every page.
my ($output,$sth,$link,$cond);
my $tags=shift;
my $catid = $tags->{catid};
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY rand()");
if ($catid){
my $cat_db = $DB->table('Category');
my $all_ids = $cat_db->children($cat_id);
push @$all_ids, $cat_id;
$cond = GT::SQL::Condition->new('sponsors', '=', 'Yes', 'isValidated','=','Yes', 'CategoryID', 'IN', $all_ids);
}
else {
$cond = GT::SQL::Condition->new('sponsors', '=', 'Yes', 'isValidated','=','Yes');
}
$sth = $search_db->select ($cond);
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link_sponsored', $link);
}
return $output;
}