UtopiaSoftware Forums

Full Version: HOW TO TRUNCATE HEADLINES ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I would like to display only the first 20 (or n number) of characters of each headline news on my home page ? Could you tell me please how to do this, since the standard configuration displays the whole headline and therefore displays in on two lines if it is too long.

Thanks a lot.

David
When you go into the Main Settings, there should be a setting like this:

Maximum News Length
If you have news truncation enabled, this is the approximate number of characters to display before providing a link to read the rest.
Hi brian

No, this is not what I wanted to do...

Suppose on the home page i have the following headlines

- Briton jailed for 40 years over U.S. and UK plots
- Fight for U.S. Congress up to voters now
- Rwanda seeks four genocide fugitives from Britain
- Soldier killed in attack on Basra base
- British and American hostages freed in Nigeria
- Reid orders offenders' bail hostels review
- Religious leaders unite to launch vaccine bond

What I would like is to display it like that

- Briton jailed for 40 years...
- Fight for U.S. Congress...
- Rwanda seeks four...
- Soldier killed in attack...
- British and American...
- Reid orders offenders'...
- Religious leaders unite...

of course, clicking on the headline brings you to the page where you can read the full news.

What you were talking about was News Length... I want to apply that to the headlines.

Thanks

David
I see what you're saying. This is for within headlines.php, right?

Find:

PHP Code:
$poster $headlines['poster']; 

Add under it:

PHP Code:
$cutstring md5(time());
$subject wordwrap($subject50$cutstring);
$subject explode($cutstring$subject);
$subject $subject[0]; 


You can then adjust the 50 to different lengths. I believe this will work.

Hi Brian

Thanks a lot, it works perfectly

PS : One more thing. And if I want to add the '...' (suspension points) after the truncation, (eg: like in my example above), where do I put that in the code ?

Dave
OOps, I forgot to say that i would like the suspension points to display ONLY if the headline is truncated (eg : longer than 50 characters).

If smaller (<50 characters), I don't want the suspension points to display since the headline is complete.

If you have any idea, that would be great.

Thx
Dave
That should be easy. Replace the first code with:

PHP Code:
$cutstring md5(time());
$subjectinit $subject;
$subject wordwrap($subject50$cutstring);
$subject explode($cutstring$subject);
if (
strlen($subjectinit) == strlen($subject))
{
$subject $subject[0];
}
else
{
$subject $subject[0].'...';


If this doesn't work, let me know. It would probably be because of the way strlen works on wordwrap'd things. I'd just have to change it up a bit.

Reference URL's