You are not logged in.
Pages: 1
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
Diffrent way.
in in file blog_include.php before
//Display existing posts, but only if post-index file existsadd
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
Just found this post & I tried the 2nd solution (with the ...) & it works! Awesome! I've been look for something like this.
Offline
Pages: 1