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

Need help with a "featured link" global.

Quote Reply
Need help with a "featured link" global.
I've got a column in my lsql_Links table called isFeatured.

When this is set to 1, I show the link in a highlighted table and placed above the rest of the links.

I'd like to develop a global, which will update the category and detailed pages and show featured links belonging the appropriate category.

Say for example, someone browses a link with the ID=100.

The following sql statement tells me which category that link belongs to if its a link.

Code:


select * from lsql_CatLinks where LinkID=100;


Say that returns the CategoryID as 31. Not sure where the Category ID is stored when I'm building a category listing page.

The following SQL statement allows me to then find the featured links in that category.

Code:
select ID,Title from lsql_Links,lsql_CatLinks where lsql_CatLinks.CategoryID=31 and lsql_Links.ID=lsql_CatLinks.LinkID and lsql_Links.isFeatured=1;


Can someone help me turn this into a global which I can use during the build process in the various templates?

Thanks!
Quote Reply
Re: [shrirch] Need help with a "featured link" global. In reply to
The closest thing I've found is this.

Code:
sub {
my $tags = shift;
my ($cat_id, $cat_name) = each %{$DB->table('Links')->get_categories($tags->{ID})};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options("ORDER BY $CFG->{build_sort_order_category}");
my $sth = $link_db->select({ CategoryID => $cat_id });
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}


How can I modify to just show return a link title of a link which has isFeatured=1?
Quote Reply
Re: [shrirch] Need help with a "featured link" global. In reply to
Just edit the following;

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

...to something like;

Code:
while (my $link = $sth->fetchrow_hashref) {
$output .= "<a href="$link->{URL}">$link->{Title}</a>";
}

... and ...

Code:
my $sth = $link_db->select({ CategoryID => $cat_id });

to...

Code:
my $sth = $link_db->select({ CategoryID => $cat_id, isFeatured => '0' });

That should hopefully do the job.

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] Need help with a "featured link" global. In reply to
Andy,

Thanks for the reply.

I have the following

Code:


sub {
my $tags = shift;
my ($cat_id, $cat_name) = each %{$DB->table('Links')->get_categories($tags->{ID})};
my $link_db = $DB->table('Links','CatLinks');
$link_db->select_options("ORDER BY $CFG->{build_sort_order_category}");
my $sth = $link_db->select({ CategoryID => $cat_id, isFeatured => '1' });
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
$output .= "<a href="$link->{URL}">$link->{Title}</a>";
}
return $output;
}


Unfortunately the output says "Unable to compiled 'featured':
Quote Reply
Re: [shrirch] Need help with a "featured link" global. In reply to
I think I've narrowed it down to the output .= statement.

Changed it to

$output .= "<a href="$link->{'URL'}">$link->{'Title'}</a>";

Still does not work. Am I missing something? I'm feeling pretty damn stupid right now as I don't know jack about perl. :(
Quote Reply
Re: [shrirch] Need help with a "featured link" global. In reply to
Sorry, should be;

$output .= qq|<a href="$link->{'URL'}">$link->{'Title'}</a>|;

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!