Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Shorten long title name with ... ?

Quote Reply
Shorten long title name with ... ?
Hi, since I am putting the most popular links on my home.html inside a table, what's the easiest way to display the long titles if over certain characters with "..." at the end so it fits in the table nicely?
Quote Reply
Re: [flybuzz] Shorten long title name with ... ? In reply to
Hi. Something like this should do :)

http://www.gossamer-threads.com/...i?post=122985#122985

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] Shorten long title name with ... ? In reply to
Hi, that's the post to shorten the description, I am looking for rather to shorten the Title link. The global code for top 10 I am using right now is:

sub {
#Top 10 sites by hits.
my ($output,$sth,$link);
my $id = shift;
my $db = $DB->table ('Links');
$db->select_options ('ORDER BY Hits DESC', 'LIMIT 10');
my $sth = $db->select ( { isValidated => 'Yes'} );
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('top_ten', $link);
}
return $output;
}


I know it's the line around $output needs to be updated... can you help me out real quick? Thanks. Smile
Quote Reply
Re: [flybuzz] Shorten long title name with ... ? In reply to
Something like this should work;

Code:
sub {

# Top 10 sites by hits.

my $length = 100;

my ($output,$sth,$link);
my $id = shift;
my $db = $DB->table ('Links');

$db->select_options ('ORDER BY Hits DESC', 'LIMIT 10');
my $sth = $db->select ( { isValidated => 'Yes'} );
while ($link = $sth->fetchrow_hashref) {
$link->{Title} = substr ($link->{Title}, 0, $length);
$link->{Title} =~ s/\s\S+?$//;
$link->{Title} .= " ...";
$output .= Links::SiteHTML::display ('top_ten', $link);
}
return $output;
}

I'm off to bed now :)

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] Shorten long title name with ... ? In reply to
Hi unfortunately didn't work, it just erases the last word on every link and replace it with ... some logic error somewhere... ?
Quote Reply
Re: [flybuzz] Shorten long title name with ... ? In reply to
I added if statement just like the other old post... seems to work now....

sub {

# Top 10 sites by hits.
my ($output,$sth,$link);
my $id = shift;
my $db = $DB->table ('Links');

$db->select_options ('ORDER BY Hits DESC', 'LIMIT 10');
my $sth = $db->select ( { isValidated => 'Yes'} );
while ($link = $sth->fetchrow_hashref) {
if(length $link->{Title}>
26 ){
$link->{Title} = substr ($link->{Title}, 0,
26 );
$link->{Title} =~ s/\s\S+?$//;
$link->{Title} .= " ...";
}
$output .= Links::SiteHTML::display ('top_ten', $link);
}
return $output;
}