Gossamer Forum
Home : Products : Gossamer Links : Discussions :

howto add banner/textlink on the top off all category pages, based on a field in database?

Quote Reply
howto add banner/textlink on the top off all category pages, based on a field in database?
Hello ALL,

Well i did a lot of 'hacks' in the past Links 2.0.
Now i am trying to understand Links SQL. Somehow i feel like a complete newbie 'again' :)....

Good here's my question:

Let's say i have added a few new fields in the links table:

field 30: advert with 3 enum value's empty/banner/special_link_text
field 31: bannerurl (value the url where the banner is located)
field 32: special_link_text (max. 80 characters of text)

Ok now i want this to happen with the category pages if i choose build all:

On top of the page it will first display banners, if there are any. Next it will display the special_link_text, if there are any. After that it will display the 'normal' links (where the links with banner/special_link_text will be displayed first).

Like this (category page):

BANNER
(graphics with url)

special_link_text
(like Gossamer-thread - the best solution for your portal)

LINKS with field advert, value banner or special_link_text, first
LINKS (rest)
(LINK with Name URL)

Ehm. I really haven't a clue where to start, maybe in Site_HTML.pm or isn't that smart to edit ? Because if there will be a update it will overwrite it?

Hope any can help me out, and understand what i mean :)

Regards Startpoint.
Quote Reply
Re: [startpoint] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Hallo all,

Well, after trying to understand the new SQLlinks and read a zillion threads i am a step closer to my solution :)

First i am trying to make the special_text_link work (then the banner will be easY:).


I did make a new global called special_text_link and make a call in category.html

Code global special_text_link:

sub {
# Show special_text_link
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Title DESC');
$sth = $search_db->select ( { advert => 'special_text_link'});
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}

Good we have a start, and it's kinda working :)

A few question about it:

- I only wanna show the links with advert = special_text_link in the cats (related cats asswell) where it belongs. Now it will be displayed in all cats... How to do this?

- Second question: now it will call the template default and use file link.html. I want to make a new file called special_text_link.html (i know how to do this:)). But the problem is that i use different template's for the cats. So how to select a template that is not the default?

So the code:
$output .= Links::SiteHTML::display ('link', $link);

Have to be:
$output .= Links::SiteHTML::display ('special_text_link', $link);
how to select a template like say it's called brokers ?

Well getting closer to the solution and learning a lot, hope any can help me on the way to become a LinksSQL expert:)....

If someone have good documentation (or know where to find it) about selecting and globals in LINKSQL, i really love to have that.

Regards startpoint.

Last edited by:

startpoint: Sep 18, 2001, 8:52 AM
Quote Reply
Re: [startpoint] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Hi,

First off, about docs, have you read:

http://gossamer-threads.com/...opic=help_guide.html

(use admin/admin to get in, it's just the demo). Make sure you look at the module documentation, and especially GT::SQL and GT::SQL::Table for examples on how to query the database.

Now, to your problem. I assume this is being called from category.html? Remember, the first argument to these is a hash of available tags. So you can do:

Code:
sub {
my $tags = shift;
my $cat_id = $tags->{ID};
..
to get the category ID of the category you are on. With that, you can change your query slightly:

Code:
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options('ORDER BY Title DESC');
$search_db->select ( { advert => 'special_text_link', CategoryID => $cat_id } );
What that will do is create a relation object and find all links that have advert set and are in the selected category.

Finally, to get the proper template, you need the Category_Template tag and pass that into display:
Code:
my $template = $tags->{Category_Template};
Links::SiteHTML::display('special_text_link', $link, { template => $template });
Let me know if this helps (I'm missing some parts like the while loop, but I hope you get the picture).

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Hi,

Thanks for your great post Alex, did help me a lot. I read all docs (just once yet:)).

Ok, u did give me allmost anything, so it wasn't hard to make this work.
Somehow i still have one problem which i don't get. Picking up the right template
doesn't work, it keeps getting the file from the default template. I do get error:

Invalid method: site_html_tekstlink (tekstlink.html) at /somewhere/SiteHTML.pm line 201.

The code is:

sub {
# Show tektlinks in the selected cats
my $tags = shift;
my ($output,$sth,$link);
my $cat_id = $tags->{ID};
my $template = $tags->{Category_Template};
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options('ORDER BY Title DESC');
$sth = $search_db->select ( { Product => 'tekstlink', CategoryID => $cat_id } );
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('tekstlink', $link, { template => $template });
}
return $output;
}


So this part:
my $template = $tags->{Category_Template};
$output .= Links::SiteHTML::display('tekstlink', $link, { template => $template });
Isn't working good i quess, or it doesn't send the var to SiteHTML.pm?

The error:
Invalid method: site_html_tekstlink (tekstlink.html) at /somewhere/SiteHTML.pm line 201.

Is because it can't find the propper file in the propper cat and die's. Well offcourse i can put tekstlink.html in the default template and it will work, but i don't want that. Somewhere is a error, i quess it 'easy' for U or someone else to solve this ?

Hope u can give my the answer.

Regards startpoint.
(I did learn a lot, again thanks Alex).
Quote Reply
Re: [startpoint] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Hi,

Try putting <%Category_Template%> on your template and see what the value is set to? That should work..

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Hi,

Well <%Category_Template%> show the right template name. Still it's getting the file (banner.html) from default template !?

Any idea's?

The code i have now is (some other field name's i used now):

sub {
# Show banner
my $tags = shift;
my ($output,$sth,$link);
my $cat_id = $tags->{ID};
my $template = $tags->{Category_Template};
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options('ORDER BY Title DESC');
$sth = $search_db->select ( { Product => 'banner', CategoryID => $cat_id } );
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('banner', $link, {template => $template} );
}
return $output;
}[/code]
Are u sure the part {template => $template} is good code?
I tried {t => $template} but that wasn't working asswell..

Hope u know a solution ?

Allready thanks...

Regards startpoint
Quote Reply
Re: [startpoint] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Shoot, that's a bug. =( Edit admin/Links/SiteHTML.pm and change:

my $code = eval "sub $sub { return Links::user_page ( '$file', shift, { dynamic => 1 } ); }";

to:

my $code = eval "sub $sub { my (\$vars, \$opts) = \@_; \$opts ||= { dynamic => 1 }; return Links::user_page ( '$file', \$vars, \$opts ); }";

and it should work.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Hi,

Well ehm, it's still not working.

I am talking about building pages static. I quess u found a bug in the dynamic mode ? :)....

It is still getting the page banner from the default template.

Code:
sub {
# Show banner
my $tags = shift;
my ($output,$sth,$link);
my $cat_id = $tags->{ID};
my $template = $tags->{Category_Template};
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options('ORDER BY Title DESC');
$sth = $search_db->select ( { Product => 'banner', CategoryID => $cat_id } );
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('banner', $link, {template => $template} );
}
return $output;
}

Any other idea's?

Allready thanks

Regards Startpoint.
Quote Reply
Re: [startpoint] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Hi,

No that would have fixed it for you too, as basically { template => $template } wasn't getting passed through to Links::user_page.

Try changing the output line to:

$output .= Links::user_page ('banner.html', $link, { template => $template } );

and see if it works.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] howto add banner/textlink on the top off all category pages, based on a field in database? In reply to
Hi,

Yeah nice Alex it's now working!!! :) ...

So now i use Links::user_page, can u tell my when to use the other part with SITEhtml ?

Regards Startpoint.