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

Category Sponsor Question

Quote Reply
Category Sponsor Question
I'm using this global to display my sponsor links for each category

<%cat_sponsor%>

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

How can I get this to display only certain categories and their sub categories? Is there an easy way to do this?

I tried this <%cat_sponsor (153)%> thinking it may work but only got errors. What I wanted was the category with ID 153 and all of it's sub cats sponsors displayed so I could add the global to every subcat page. That way when there is only a link or 2 it doesn't look so bad

Thanks,

Craven

Last edited by:

craven32: Mar 7, 2004, 12:05 PM
Quote Reply
Re: [craven32] Category Sponsor Question In reply to
Try changing
my $catid = $tags->{'category_id'};
to
my $catid = shift;
and delete the my $tags line.
Quote Reply
Re: [afinlr] Category Sponsor Question In reply to
Hi,

That ended up giving me a fatal error. I tried a few combinations of that but couldn't seem to get the right one.

Craven
Quote Reply
Re: [craven32] Category Sponsor Question In reply to
Try;

Code:
<%cat_sponsor($ID)%>

...and replace;

Code:
my $tags=shift;
my $catid = $tags->{'category_id'};

with;

Code:
my $catid = $_[0] || '12345';

That should sort it.

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: [craven32] Category Sponsor Question In reply to
Change <%cat_sponsor (153)%> to <%cat_sponsor('153')%>
Quote Reply
Re: [afinlr] Category Sponsor Question In reply to
That's just perfect! Works great. THANKS!!

I have one more global I was hoping this would work on but it doesn't. This one displays newest links or top rated links. I'm trying to get the same results with this code. But when I try the method above i get

Unable to compile "top_rated_cat" error

sub {
my ($all_ids,@list,$output);
my $tags = shift;
my $cat_id = $tags->{ID};
$all_ids = $DB->table('Category')->children($cat_id);
push @$all_ids, $cat_id;
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options ('ORDER BY Add_Date DESC LIMIT 5');
my $condition = GT::SQL::Condition->new( 'isValidated','=','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;
}
Quote Reply
Re: [craven32] Category Sponsor Question In reply to
Are you sure you put

my $cat_id = shift;
Quote Reply
Re: [afinlr] Category Sponsor Question In reply to
I named the global top_rated_by_cat

I replaced this

my $tags = shift;
my $cat_id = $tags->{ID};

With

my $catid = shift;

__________________________________________

And then put this in the category template

<%top_rated_by_cat('949')%>

___________________________________________

And this is still the error I receive.

Unable to compile 'top_rated_by_cat':


Thanks,

Craven
Quote Reply
Re: [craven32] Category Sponsor Question In reply to
In Reply To:
I replaced this

my $tags = shift;
my $cat_id = $tags->{ID};

With

my $catid = shift;[/quote]

This is what I meant - in this global you are using a different variable name so you need to replace it with

my $cat_id = shift;

Last edited by:

afinlr: Mar 8, 2004, 10:03 AM
Quote Reply
Re: [afinlr] Category Sponsor Question In reply to
Blush OK I guess I need to pay a lot more attention! That does work great.

Thanks for all the help. I can get back to work now.

Craven
Quote Reply
Re: [afinlr] Category Sponsor Question In reply to
I just ran into a small problem with the cat_sponsor global.

On the root category it displays 19 links and all subcats display 9. It is set to LIMIT 10 so I have no clue why this is happening.

It is also repeating links too. The exact same link was displayed 3 times in the list of sponsors. Is there a way to get it to stop listing the same link multiple times?

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

Last edited by:

craven32: Mar 8, 2004, 10:37 AM
Quote Reply
Re: [craven32] Category Sponsor Question In reply to
Deja vu.

http://www.gossamer-threads.com/...i?post=263029#263029
Quote Reply
Re: [afinlr] Category Sponsor Question In reply to
I tried this but kept getting repeats. Here are 4 strings I tried. The first one idn't work at all becauase I have no condition 2. The rest worked but had repeats.

$sth = $search_db->select (['Distinct LinkID','Links.*'], $cond2 );

$sth = $search_db->select (['Distinct LinkID','Links.*'], ($cond) );

$sth = $search_db->select (['Distinct LinkID','Links.*'], $cond );

$sth = $search_db->select (['Distinct LinkID','Links.*'],$cond);
Quote Reply
Re: [craven32] Category Sponsor Question In reply to
Can't see why the last one doesn't work. Can you just paste the global you are using again - just so I can check that the change is in the right place.
Quote Reply
Re: [afinlr] Category Sponsor Question In reply to
This is it.

sub {
# Displays the sponsored links on every page.
my ($output,$sth,$link,$cond);
my $catid = shift;
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY rand()", "LIMIT 10");
if ($catid){
my $cat_db = $DB->table('Category');
my $all_ids = $cat_db->children($catid);
push @$all_ids, $catid;
$cond = GT::SQL::Condition->new('Sponsor', '=', 'Yes', 'isValidated','=','Yes', 'CategoryID', 'IN', $all_ids);
}
else {
$cond = GT::SQL::Condition->new('Sponsor', '=', 'Yes', 'isValidated','=','Yes');
}
$sth = $search_db->select (['Distinct LinkID','Links.*'],$cond);
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('linktop10', $link);
}
return $output;
}
Quote Reply
Re: [craven32] Category Sponsor Question In reply to
Well I can't see anything wrong with that. Which version of mysql are you using?

Can you try changing order by rand() to something else and see whether you still get multiples?