pluck
pluck 4.7 out now, download it today!

pluck support forums

for all your questions about the easiest CMS on the planet

You are not logged in.

Announcement

New registrations are disabled for some spam problems. New registrations will be avaliable soon. If you want to help to keep forum away from spam - contact us.
Please post your bug reports on Launchpad.

#1 26-06-2009 12:44:44

Methuselah
Member
Registered: 14-03-2009
Posts: 63

Blog Truncation Solution

This is for anyone who was interested in being able to have shorter news posts on the front page of the blog, and then only viewing the whole post when you click "read more"..

Its a very simple and clean way to truncate posts on the front page of the blog, although it could really do with having a trailing '...' once its trimmed down the words.. anyone who can offer a suggestion of how to implement trailing dots  is welcome, i'ma php newbie so just doin what i can really.

Firstly browse thru data/modules/blog/pages_site/ and make a backup of 'blog_include.php'

Now open the original blog_include.php and edit replace the line that says

<?php echo $post_content ?>

with

<?php 
$truncated = substr($post_content,0,strpos($post_content,' ',120));
echo $truncated;
?>

Then set 120 to however many characters you want to allow before it trims the sentance.

I'm sure there are ways to make it cut at the firest line break or full stop, although  alot of the other truncation php examples i followed simply didnt work, this did and it was neat, so i kept it!

Hope its usefull to anyone whos posted asking about this.

Offline

#2 26-06-2009 16:52:42

a_bach
developer/module guru
From: Poland
Registered: 24-11-2008
Posts: 439
Website

Re: Blog Truncation Solution

Diffrent way.

in in file blog_include.php before

//Display existing posts, but only if post-index file exists

add

include("data/modules/blog/functions.php");

Now replace

<?php echo $post_content ?>

with

<?php echo cutString($post_content,128); ?>

And last change - in file data/modules/blog/functions.php add before last line ?>

function cutString($txt,$x) {
$tlen = strlen($txt);
if($x < 1) return '';
if($x >= $tlen - 1) return $txt;
while ($txt{$x} != ' ' && ++$x < $tlen);
$new = substr($txt, 0, $x);
return $new.'...';
}

Offline

#3 12-09-2009 14:35:34

jellisontech
Member
From: Maine
Registered: 10-01-2009
Posts: 99

Re: Blog Truncation Solution

Just found this post & I tried the 2nd solution (with the ...) & it works!  Awesome!  I've been look for something like this.

Offline

Board footer

Powered by FluxBB