Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-03-14 14:03:00

dingoboy
Member
Registered: 2006-09-07
Posts: 48

Reduce length of titles?

I’m looking for a way to reduce the length of a <txp:title />, so that if its length exceeds more than 30 characters, for instance, it is cut off. Please notice that I’m not talking about wrapping the titles. See my example below.

Example:

Original: This is a long and dreadful title
Reduced: This is a long and dre…

I haven’t managed to find a plugin or the like, for this purpose.

Offline

#2 2007-03-14 15:12:52

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Reduce length of titles?

Perhaps something like this (not tested):

<txp:php>
  preg_match('/^(.{0,30})(.*)$/u', title(array()), $match);
  echo $match[1];
  if (strlen($match[2])) echo '...';
</txp:php>

Offline

#3 2007-03-14 15:47:16

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Reduce length of titles?

Just for consistency with the current Textpattern output, I suggest to change the three dots to an ellipsis.

<txp:php>
  preg_match('/^(.{0,30})(.*)$/u', title(array()), $match);
  echo $match[1];
  if (strlen($match[2])) echo '…';
</txp:php>

La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2007-03-14 19:00:48

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: Reduce length of titles?

sab_substr

<txp:sab_substr limit="30" trail="&#8230;"><txp:title /></txp:sab_substr>

Offline

#5 2007-03-14 19:02:51

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Reduce length of titles?

sab_substr isn’t UTF-8 safe.

Offline

#6 2007-03-15 08:30:02

dingoboy
Member
Registered: 2006-09-07
Posts: 48

Re: Reduce length of titles?

Thanks a lot! :-)

Offline

Board footer

Powered by FluxBB