Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#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
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
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>
Offline
#4 2007-03-14 19:00:48
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Reduce length of titles?
<txp:sab_substr limit="30" trail="…"><txp:title /></txp:sab_substr>
Offline
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
Pages: 1