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

New links by main category

Quote Reply
New links by main category
Hi, this is my current new link global to get the number of new links for a category and all categories under it. Its not working, not sure why, and also how do i make it so it only displays on main category pages?

sub {
my $catid = shift;
my ($output,$link);
my $all_ids = $DB->table('Category')->children($catid);
push @$all_ids, $catid;

my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('ORDER BY Add_Date DESC,Timestmp DESC,Title Limit 10');
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids,'isValidated', '=', 'Yes');
my $sth = $table->select($cond);

while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link_new', $link);
}

return $output;
}
Quote Reply
Re: [kzap] New links by main category In reply to
What do you mean by "not working" ?

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: [kzap] New links by main category In reply to
I don't think you need the Category table as well as the CatLinks table in your $search_db variable.

The select_options line looks like it might be a problem - do you get an error message?
Quote Reply
Re: [afinlr] New links by main category In reply to
it says its unable to compile

i removed the category table from the search_db but it does need the catlinks if its going to get all the links from the category specified. I guess its giving an error since it cant order that way in the catlinks table? shouldnt the tables just join and be ordered?
Quote Reply
Re: [kzap] New links by main category In reply to
Well copying and pasting your global and trying it gave me a clear error message:

Unable to compile 'test_global': Global symbol "$table" requires explicit package name at (eval 984) line 10.

Last edited by:

afinlr: Oct 4, 2003, 11:29 AM
Quote Reply
Re: [afinlr] New links by main category In reply to
ah ok it was the $table, it shouldnt have been there. Anyway I got it working, it can be by a certain category ( <%global($ID)%> ) or all categories ( <%global(0)%> )

sub {
my $catid = shift;
my ($output,$link,$sth);

if ($catid > 0)
{
my $all_ids = $DB->table('Category')->children($catid);
push @$all_ids, $catid;
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ('ORDER BY Add_Date DESC,Timestmp DESC,Title','LIMIT 10');
my $cond = GT::SQL::Condition->new(['CategoryID', 'IN', $all_ids], ['isValidated', '=', 'Yes']);
$sth = $search_db->select($cond);
}
else
{
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC,Timestmp DESC,Title', 'LIMIT 10');
$sth = $search_db->select ( { isValidated => 'Yes' });
}

while ($link = $sth->fetchrow_hashref)
{
$output .= Links::SiteHTML::display ('link_new', $link);
}
return $output;
}
Quote Reply
Re: [kzap] New links by main category In reply to
Hello,

I seek to use the global one with this code on my page :

<%top10_news_links%>
<%loop top10_news_links_loop%>
<%include link_category.html%>
<%endloop%>

Thank you for your assistance.

Mick