Gossamer Forum
Quote Reply
Ultra Globals
Hi Andy,

Your Ultra Globals is great... :)

When using:

<%Plugins::ULTRAGlobals::Get_Top_Links(10)%>
<%if top100_loop.length%>
<%loop top100_loop%>
<%include link-chiquito.html%>
<%endloop%>
<%endif%>

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


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?

Thanks Andy,

Juan Carlos
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
Quote Reply
Re: [Andy] Ultra Globals In reply to
Hi Andy,

Both are broken....

The first global gives me this error:
Unable to compile 'get_top_links_in_cat': Global symbol "$table" requires explicit package name at (eval 31) line 11.
(btw, the call with sample and the fill global call sample are different. But both are broken).

The otherone just breaks the site.

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

Can you try the modified versions above?

my $sth = $table->select

...needed removing from the first global. Also, the sub { bit had an extra space between it (so I'm amazed GLinks even recognised it as a globalm and not just plain text <G>)

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] Ultra Globals In reply to
Thanks for your quick help Andy, as always.

Neither work now...
The first one is just empty, and the second still breaks the site.

:(
Quote Reply
Re: [Gorospe] Ultra Globals In reply to
Can you send me GLinks details, and I'll take a quick look for you (also, where they are being called =))

Cheers
Quote Reply
Re: [Gorospe] Ultra Globals In reply to
Wait, the first one works... I tried the other call and works fine. Or at least it displays something... :)
Quote Reply
Re: [Gorospe] Ultra Globals In reply to
So its just the second one not working 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] Ultra Globals In reply to
Second one breaks...

The first one aparently works fine.
Quote Reply
Re: [Gorospe] Ultra Globals In reply to
Hi,

Should work fine now =)

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

(I've removed it from your category.html, as I just put it in to test =))

Basically, this line:

my $cat = shift;

..should have been:

my $cat = $_[0];

=)

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] Ultra Globals In reply to
Works great Andy,

Thank you very much.

JC