Gossamer Forum
Home : Products : Gossamer Links : Discussions :

newest links added question

Quote Reply
newest links added question
Hi
i am using the following sub to display the newest 5 links added to my directory:

sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY ADD_DATE DESC Limit 4');
$sth = $search_db->select ( { isNew => 'Yes'});
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link1', $link);
}
return $output;
}

is there a way to limit the number of characters being displayed to an x number for each link?
Sort of the sam in yahoo subcategory mod
Some titles are so long and take over 2 lines and the page will look ugly


Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] newest links added question In reply to
sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY ADD_DATE DESC Limit 4');
$sth = $search_db->select ( { isNew => 'Yes'});
while ($link = $sth->fetchrow_hashref) {
$link->{Title} =~ s,^(.{50}).*$,$1...,;
$output .= Links::SiteHTML::display ('link1', $link);
}
return $output;
}
Quote Reply
Re: [PaulW] newest links added question In reply to
thanks
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] newest links added question In reply to
You can also add a new sub called short_title:

sub {
my $tags = shift;
my $titl = $tags->{Title} or return "No description.";
length $titl < 18 and return $titl;
my $short = substr ($titl, 0, 18);
$short =~ s/\s\S+?$//;
$short .= " ...";
return $short;
}

And then use <%short_title%> instead of <%Title%> in your link tag. This was originally written to shorten description tags, which it works great for that too.
Quote Reply
Re: [BryanL] newest links added question In reply to
You don't want:

$short =~ s/\s\S+?$//;
Quote Reply
Re: [PaulW] newest links added question In reply to
I guess it's not necessary, but that line does prevent words from getting prematurely cut off. It just depends how important the exact character count is, this sub will result in titles of varying length, but none longer than desired.