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

Re: [Gorospe] Ultra Globals

Quote Reply
Re: [Gorospe] Ultra Globals In reply to
Hi,

Quote:
Your Ultra Globals is great... :)

Cool

Quote:
To get top links, works great. How do I get the same variable but of a subcategory and everything under it?

That requires a bit of rewriting of the function, so try the global below (a modified version of the global, which lets you pass in a category ID):

get_top_links_in_cat
Code:
sub {

my $limit = $_[0] || 100;

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

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 @output;
while (my $link = $sth->fetchrow_hashref) {
push (@output, $link);
}

return { top100_loop => \@output };

}

Call with:

<%get_top_links_in_cat(10,'category_id')%>

..i.e:

Code:
<%get_top_links_in_cat(10,$category_id)%>
<%if top100_loop.length%>
<%loop top100_loop%>
<%include link-chiquito.html%>
<%endloop%>
<%endif%>

Quote:
In the same page I want to display:

<%Plugins::ULTRAGlobals::New_Links_By_Category($ID)%>
<%loop new_links_in_this_cat%>
<%include link-chiquito.html%>
<%endloop%>

How do I limit the number to 10?


Well, there are 2 options really.

1) You can open up /admin/Plugins/ULTRAGlobals.pm, and find:

Code:
sub New_Links_By_Category {

..in that function, there is this line:

Code:
$db_obj->select_options ('ORDER BY Add_Date DESC Limit 5');

..just change the "5" to whatever number you want :)

..or, you can make a new global that will do it (so you dont have to edit the .pm file, which will cause problems later down the line when new versions of the plugin are released :))

new_links_by_category
Code:
sub {

my $cat = shift;
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 Add_Date DESC Limit $_[1]");

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

}


Code:
<%new_links_by_category($ID,10)%>
<%loop new_links_in_this_cat%>
<%include link-chiquito.html%>
<%endloop%>

Hopefully that will be ok ;)

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: Sep 13, 2008, 9:11 AM
Subject Author Views Date
Thread Ultra Globals Gorospe 6250 Sep 12, 2008, 1:53 PM
Thread Re: [Gorospe] Ultra Globals
Andy 6117 Sep 13, 2008, 12:05 AM
Thread Re: [Andy] Ultra Globals
Gorospe 6087 Sep 13, 2008, 9:10 AM
Thread Re: [Gorospe] Ultra Globals
Andy 6106 Sep 13, 2008, 9:12 AM
Thread Re: [Andy] Ultra Globals
Gorospe 6110 Sep 13, 2008, 9:26 AM
Post Re: [Gorospe] Ultra Globals
Andy 6094 Sep 13, 2008, 9:28 AM
Thread Re: [Gorospe] Ultra Globals
Gorospe 6101 Sep 13, 2008, 9:29 AM
Thread Re: [Gorospe] Ultra Globals
Andy 6099 Sep 13, 2008, 9:49 AM
Thread Re: [Andy] Ultra Globals
Gorospe 6112 Sep 13, 2008, 9:51 AM
Thread Re: [Gorospe] Ultra Globals
Andy 6132 Sep 13, 2008, 9:58 AM
Post Re: [Andy] Ultra Globals
Gorospe 6076 Sep 13, 2008, 10:12 AM