SimplePortal

Development => Feature Requests => Topic started by: mforum on January 03, 2010, 05:23:27 AM

Title: Post block
Post by: mforum on January 03, 2010, 05:23:27 AM
It would be nice to have a block that grabs a post and shows it with a Read More link.
We can put id of post and a limit in lines shown.

Now i use the following php block :

Code: [Select]
<?php $post ssi_fetchPosts(148845NULLNULL);
echo 
$post[0]['body'], '<br />'?>

it just shows  the whole post.  :|

smf 2 rc2
SP 2.3.1
Title: Re: Post block
Post by: grafitus on January 03, 2010, 05:58:46 AM
You try, please:
Code: [Select]
global $smcFunc;
$length = 50;
$post = ssi_fetchPosts(50, NULL, NULL);

if (!empty($length) && $smcFunc['strlen']($post[0]['body']) > $length)
{
$post[0]['body'] = $smcFunc['substr']($post[0]['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($post[0]['body'], ' '), strrpos($post[0]['body'], '<'));

if ($cutoff !== false)
$post[0]['body'] = $smcFunc['substr']($post[0]['body'], 0, $cutoff);
$post[0]['body'] .= '<a href="' . $post[0]['href'] . '">...</a>';
}
echo $post[0]['body'];
Title: Re: Post block
Post by: mforum on January 03, 2010, 08:15:47 AM
Its perfect ! Thank you !!  :thumbsup:
Title: Re: Post block
Post by: curlin on February 01, 2010, 03:47:20 PM
     Hi

  Just added the code in a custom php block but nothing is showing. Just empty. Is there something pertaining to my forum that i have to enter in the block code?
SimplePortal 2.3.8 © 2008-2024, SimplePortal