TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,970
  • Latest: bynw
Stats
  • Total Posts: 196,047
  • Total Topics: 21,336
  • Online today: 374
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 100
  • Total: 100

Frontpage forum posts with a "read more" function, similar to Wordpress.

Started by mrsd99, November 11, 2013, 03:26:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

WillyP

Of course, getting help on the SMF board is an exercise in frustration. The signal to noise ratio over there is pretty bad lately. I don't think either Kindred or margrett did more than a cursory glance at my post.

Anyway, I did find this: SMF Function DB - ssi_boardNews

From that page:
QuoteParameter $length

Expected type: Integer
Description: If specified, posts longer than this will be shortened and have "..." or a "Read More" link appended
So it looks like a 'read more' link is optional, but I haven't found any documentation on how to activate it.

IchBin, I've been using the code on my site for years, I may have altered ssi.php to get the read more link, but it probably got overwritten in an update. I have never had any layout issues due to breaking html. So I'm pretty sure this is handled ok.

mrsd99

Quote from: WillyP on November 12, 2013, 08:18:20 PM
Of course, getting help on the SMF board is an exercise in frustration. The signal to noise ratio over there is pretty bad lately. I don't think either Kindred or margrett did more than a cursory glance at my post.

Anyway, I did find this: SMF Function DB - ssi_boardNews

From that page:
QuoteParameter $length

Expected type: Integer
Description: If specified, posts longer than this will be shortened and have "..." or a "Read More" link appended
So it looks like a 'read more' link is optional, but I haven't found any documentation on how to activate it.

IchBin, I've been using the code on my site for years, I may have altered ssi.php to get the read more link, but it probably got overwritten in an update. I have never had any layout issues due to breaking html. So I'm pretty sure this is handled ok.

Thanks for all your help WillyP. I doubt I could have solved this without you. I read the topic on SMF as well. I'm still pretty confused as to exactly what I need to put and where in order to get this function.

Do I place this code in a phpbox?:
array ssi_boardNews ([int $board[, int $limit[, int $start[, int $length[, string $output_method]]]]])

WillyP

No, here is the code that worked for me, obviously you might need to tweak the html a bit:

echo'<h3>Soupe Du Jour:</h3><br />
<div class="news_item">';
$readout=ssi_boardNews(10,1,null, 3500, 'block');
foreach ($readout as $topic) {
    echo '<h3 class="news_header">',$topic['subject'],'</h3>
    <div class="news_body">', $topic['body'],
    '</div>
    <a href="', $scripturl,'?topic=', $topic['id'],'">Read More</a><br />'
     ,$topic['link'],'|',$topic['new_comment'],
'</div>'
     ;
}


In the third line, 10, is the board number, 1 is the number of posts to pull, and 3500 is the number of characters.

mrsd99

That's awesome willy! I'm going to my part time job right now, but I will post my results when I get home! Hopefully this will help someone else as well.

IchBin

I don't see how ssi_boardNews() could show a "read more" link in the output anywhere. I see how/where it puts the "..." at the character limit, but I don't see any read more links.

There is the "2 comments | Write Comment" link of course. But I don't see anything else.

IchBin

Here's some quick code. Just copying what ssi_boardNews() is doing, but adding the read more link (hard coded text).

if (!empty($context['TPortal']['frontpage_limit_len']))
$row['body'] = $smcFunc['substr']($row['body'], 0, $context['TPortal']['frontpage_limit_len']);

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

if ($cutoff !== false)
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$row['body'] .= '... <p><strong><a href="'. $scripturl. '?topic='. $row['id']. '">Read More</a></strong></p>';


This bit of code will need to go in a few places. Or just one, if you only want to change the current frontpage option you have selected. If your frontpage option is to show only forum posts then you'll need to look for this section in TPortal.php.

elseif(in_array($context['TPortal']['front_type'], array('forum_only', 'forum_selected')))

After that line you'll find this section:
while($row = $smcFunc['db_fetch_assoc']($request))
{
// some needed addons
$row['rendertype'] = 'bbc';
$row['frame'] = 'theme';


You can add the code I've given right before the //some needed addons line. Let me know if it doesn't work for you. You'll need to add this to all the different sections if you want it to apply to all the different frontpage options.  (Only forum-posts,  Selected topics only,  Forum-posts and articles - sorted on date)

mrsd99

Thank you thank you IchBin! That worked perfectly for me!! I only needed to change that one file, since those were the settings I was using. You are the man!!  O0

IchBin

Glad to help.  Just added the code to TP's repository. So if I ever get around to release another version, it should be in there. :)

mrsd99

Quote from: IchBin™ on November 13, 2013, 02:46:10 AM
Glad to help.  Just added the code to TP's repository. So if I ever get around to release another version, it should be in there. :)
I feel honored to have had a part in the betterment of a wonderful software.  :D

WillyP

Quote from: IchBin™ on November 13, 2013, 12:07:01 AM
I don't see how ssi_boardNews() could show a "read more" link in the output anywhere. I see how/where it puts the "..." at the character limit, but I don't see any read more links.

There is the "2 comments | Write Comment" link of course. But I don't see anything else.

Huh? I'm confused... you gave me code yourself on the SMF site. It's posted in the previous post of mine, and working on my site: Planet Descent

This website is proudly hosted on Crocweb Cloud Website Hosting.