Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Show latest links with the exception of one category...

Quote Reply
Show latest links with the exception of one category...
Hi,

I want to show new 5 links on my homepage. There is a nice global for that. But I want this with the exception of one category.

Can anybody help me with this?

Thanks,
Ron
Quote Reply
Re: [rsahertian] Show latest links with the exception of one category... In reply to
The way I would do this would be to add a new field to the Category table; something like 'ShowNew' and make it enum 'Yes' or 'No'. Then set the default to be Yes and change it to No just for the category that you don't want to be shown. Then in your global you can add a restriction to the select statement. You'll also need to add CatLinks and Category to your table.

my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 5');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes', ShowNew => 'Yes' });
Quote Reply
Re: [afinlr] Show latest links with the exception of one category... In reply to
Thanks again Laura,

Works......
xxx
WinkWinkWink
Quote Reply
Re: [rsahertian] Show latest links with the exception of one category... In reply to
Is there a way of doing this for specific categories ?

lets say I have 3 categories: cars, boats and trucks

I want to list the top 5 for cars then top 5 for boats and then for trucks and that would include anything added to there subcategories.

would it be possible to specify by the category ID ?
Quote Reply
Re: [incik] Show latest links with the exception of one category... In reply to
Yes it is possible. What do you mean by 'top'? Do you mean new or something else?
Quote Reply
Re: [afinlr] Show latest links with the exception of one category... In reply to
sorry, I meant new

the latest links

do you have a global that I can do this with ?

Thanks
Quote Reply
Re: [incik] Show latest links with the exception of one category... In reply to
You'll need to call this something like cat_new and then use the tag <%cat_new('2')%> to show the newest 5 links in category 2 and all its subcategories.

sub {
my ($cat_id,$all_ids,@list,$output,$link_db,$condition);
$cat_id = shift;
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
$link_db = $DB->table('Links','CatLinks','Category');
$link_db->select_options ("ORDER BY Add_Date DESC LIMIT 5");
$condition = GT::SQL::Condition->new( 'isValidated','=','Yes','isNew','=','Yes','CategoryID', 'IN', \@$all_ids);
my $sth = $link_db->select($condition);
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}