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

Great global but little problem....

Quote Reply
Great global but little problem....
 
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
Not much help if you don't actually make a post Wink

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] Great global but little problem.... In reply to
This is really curious as I did post something.

Any way here is it:

This global is great: it allows me to display on the front page the latest xx links. However, there is a problem when a link belongs to several categories: it appears duplicated. For example, if a link belongs to 3 categories, the global will diplay it 3 times.

So what should I add so no matter how much categories a links belongs to, it will be displayed only once ?

Thanks in advance,
Brakkar

Quote:
sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 30');
my $cats = [35,42];
my $cond = GT::SQL::Condition->new( 'CategoryID','IN', $cats); $cond->not; my $cond2 = GT::SQL::Condition->new($cond, 'isValidated','=','Yes'); $sth = $search_db->select ( $cond2 ); my $x = 0; while ($link = $sth->fetchrow_hashref) {
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
Links::init_date();
$link->{Add_Date} = GT::Date::date_transform ($link->{Add_Date}, $CFG->{date_db_format}, $CFG->{date_user_format});
if ($x < 15) {
$output .= Links::SiteHTML::display('linkfront', $link);
}
else {
$output .= Links::SiteHTML::display('linkfront', $link);
}
$x++;
}
return $output;
}
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
Try this:

$sth = $search_db->select (['Distinct LinkID','Links.*'], $cond2 );
Quote Reply
Re: [afinlr] Great global but little problem.... In reply to
Is there a special line I should place it ?
I tried but it won't load.

Cordially,
Brakkar
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
Sorry for my bad explanation. Try replacing

sth = $search_db->select ($cond2 );

with

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

Also, if you have a prefix on your tables then it will need to be prefix_Links.* rather than Links.* - replacing prefix with whatever your prefix is.
Quote Reply
Re: [afinlr] Great global but little problem.... In reply to
Works great thanks.
Do you know if this kind of global will work on the next version of linksql ?

Thanks,
Brakkar
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
I certainly hope so - otherwise there will be a lot of people with a lot of problems Wink
Quote Reply
Re: [afinlr] Great global but little problem.... In reply to
Ok, and do you have a trick to limit the number of characters from the <%title%> that will be generated by the global ? I mean I use this global to generate a very simple display using a 'linkfront.html' file that only displays the linked title of the links, but I would like to limit it to lets say 40 characters and add "..." where it is cut...

Should the tag be modified ? If yes how ?

Thanks in advance,
Brakkar

Last edited by:

brakkar: Mar 12, 2004, 4:11 PM
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
You need to just add the following:

Code:
if (length($link->{Title} > 40) {
$link->{Title} = substr($link->{Title}, 0, 40) . "...";
}

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Great global but little problem.... In reply to
Well, I try to add this in another variable, and it says it is unable to compile.
Here is the other variable, with your code inside:

Quote:

sub {
use GT::Date;
my ($output,$sth,$link);
my $days = shift;
my $limit = shift;
my $date = GT::Date::date_get();
my $newdate = GT::Date::date_sub($date,$days);
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY Hits DESC","LIMIT $limit");
my $cond = GT::SQL::Condition->new( 'Add_Date', '>', $newdate, 'isValidated', '=', 'Yes');
if (length($link->{Title} > 40) {
$link->{Title} = substr($link->{Title}, 0, 40) . "...";
}

$sth = $search_db->select (['Distinct LinkID','Links.*'], $cond );
while ($link = $sth->fetchrow_hashref) {
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display ('poplinkfront', $link);
}
return $output;
}


Do you know why it doesn't work ?

Thanks in advance,
Brakkar
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
It needs to go after:
Code:
while ($link = $sth->fetchrow_hashref) {
but before:
Code:
$output .= Links::SiteHTML::display ('poplinkfront', $link);

Philip
------------------
Limecat is not pleased.

Last edited by:

fuzzy logic: Mar 12, 2004, 5:59 PM
Quote Reply
Re: [fuzzy logic] Great global but little problem.... In reply to
--edit - wait--

Last edited by:

brakkar: Mar 12, 2004, 6:04 PM
Quote Reply
Re: [fuzzy logic] Great global but little problem.... In reply to
Hmmm, I tried:

sub {
use GT::Date;
my ($output,$sth,$link);
my $days = shift;
my $limit = shift;
my $date = GT::Date::date_get();
my $newdate = GT::Date::date_sub($date,$days);
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY Hits DESC","LIMIT $limit");
my $cond = GT::SQL::Condition->new( 'Add_Date', '>', $newdate, 'isValidated', '=', 'Yes');
$sth = $search_db->select (['Distinct LinkID','Links.*'], $cond );
while ($link = $sth->fetchrow_hashref) {
if (length($link->{Title} > 40) {
$link->{Title} = substr($link->{Title}, 0, 40) . "...";
}

$output .= Links::SiteHTML::display ('poplinkfront', $link);
}
return $output;
}

But it still can't compile...

Cordially,
Brakkar
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
sorry, I missed a closing parenthesis

change:
Code:
if (length($link->{Title} > 40) {
to:
Code:
if (length($link->{Title}) > 40) {

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Great global but little problem.... In reply to
Well well... I must say that you rules.

Thank you very much.

Brakkar
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
Unfortunately that's about the extent to which I can help anyone in Links SQL. I'm a long time Links 2.0 user (4+ years), but I've only been running Links SQL for a few weeks now, so I have to say so far I'm not too bright when it comes to all these new features.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
Just an extra tip to add onto Fuzzy logic's mod:

if (length($link->{Title}) > 40) {
$link->{Title} = substr($link->{Title}, 0, 40);
$link->{Title} =~ s/\s\S*$//; #This line should stop half a word appearing at the end of the Title
$link->{Title} .= "...";
}
Quote Reply
Re: [afinlr] Great global but little problem.... In reply to
OK, here is one of the global i'm using:

sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 7');
my $cats = [5,14,17,12,11,33,35,34,8];
my $cond = GT::SQL::Condition->new( 'CategoryID','IN', $cats); my $cond2 = GT::SQL::Condition->new($cond, 'isValidated','=','Yes'); $sth = $search_db->select (['Distinct LinkID','Links.*'], $cond2 ); my $x = 0; while ($link = $sth->fetchrow_hashref) {
$link->{'detailed_url'} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
Links::init_date();
$link->{Add_Date} = GT::Date::date_transform ($link->{Add_Date}, $CFG->{date_db_format}, $CFG->{date_user_format});
if ($x < 3) {
$output .= Links::SiteHTML::display('link2', $link);
}
else {
$output .= Links::SiteHTML::display('poplinkfront2', $link);
}
$x++;
}
return $output;
}

For some reason, when I add the <%if isNew%> tag on my link2.html and poplinkfront2.html templates, ALL the links produced by this global will be flagged as NEW even if they are not. My new link cut off is 2 days, and even a link 1 year old displayed by this global will be considered new.

Does anyone know why ?

Thanks in advance,
Brakkar
Quote Reply
Re: [brakkar] Great global but little problem.... In reply to
Try <%if isNew eq 'Yes'%> - does that make any difference?
Quote Reply
Re: [afinlr] Great global but little problem.... In reply to
Thanks for your help, it works.

Brakkar