Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Shorter description length on links page

Quote Reply
Shorter description length on links page
I would like to shorten the description length on the listing page since some maybe very long. This will force the user to click to the detailed page for all the information. I would like it to display a certain number of charaters then three dots

Quote:
example sentence ...
Quote Reply
Re: [Soren] Shorter description length on links page In reply to
Hi,

Something like this should work:

Global name: trim_desc

Code:
sub {
my $desc = $_[0];
my $num_chars = $_[1] || 500;

if (length $desc > $num_chars) {
$desc = substr($desc, 0, $num_chars) . '...';
}
return $desc;
}

Call with:

<%trim_desc($Description,100)%>

The "100" is the number of charachters (inc spaces) that you want to show. If its more than that number, it will get "trimmed" down, and ... added to the end.

Hope it works =)

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] Shorter description length on links page In reply to
Perfect! Thanks Andy
Quote Reply
Re: [Andy] Shorter description length on links page In reply to
Hi Andy or any Perl'ers on the forum :)

How would i setup this sub to preserve the words?

So instead of:

The quick brown fox jum...

the quick brown fox jumped...

Thanks



Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile

Quote Reply
Re: [Chas-a] Shorter description length on links page In reply to
Hi,

You would need a different global for that. Untested, but should work:

trim_field
Code:
sub {

my $num_chars_max = $_[0];
my $string = $_[1];

if (length $string < $num_chars_max) { return $string; } else {

my $length;
my @split = split /\s+/, $string;

my @back;
foreach (@split) {
$length += length($_);
push @back, $_;
if ($length >= $num_chars_max) { last; }
}

return join(" ", @back) . "...";

}

}
Then call with:

Code:
<%trim_field(length,$Description)%>

..ie

Code:
<%trim_field(250,$Description)%>

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] Shorter description length on links page In reply to
Works a charm. Thanks!



Comedy Quotes - Glinks 3.3.0, PageBuilder, StaticURLtr, CAPTCHA, User_Edit_Profile