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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 468
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 182
  • Total: 182

Show a whole post in "Recent posts".

Started by JPDeni, July 12, 2006, 03:51:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JPDeni

Is there a way to show a whole post in the "recent posts" on the front page? I would like to be able to have an Announcements forum in SMF and show the whole most recent post and 4 partial less recent ones.

JPDeni

I got it worked out. I copied function tp_boardNews from TPortal.php and tweaked it a bit. Works like a charm.

IchBin

If you would be so kind to share that in this thread we could move this to the block code snippets forum for a nice little addon.

JPDeni

#3
Happy to.

Put the following in a Center Block or Frontpage Block -- a phpbox, please. Edit the marked lines at the beginning to match the board where your announcements live and how many you want to display. Way down at the bottom is where you can format how you want your posts to look.


global $scripturl, $db_prefix, $txt;
global $settings, $modSettings, $context;

loadLanguage('Stats');

// Edit below to fit your needs

$limit =5;       //total nuber of posts to be displayed
$start =0;       //start with the most recent post (I can't imagine wanting to change this)
$board = 20;     //the number of the board to get the posts from
$length =300;    //how many characters before the cutoff -- applies to the second and subsequent posts


// Make sure the board exists
$request = db_query("
   SELECT ID_BOARD
   FROM {$db_prefix}boards
   WHERE " . ($board === null ? '' : "ID_BOARD = $board
   ") . " LIMIT 1", __FILE__, __LINE__);

if (mysql_num_rows($request) == 0)
{
  die($txt['smf_news_error2']);
}
list ($board) = mysql_fetch_row($request);
mysql_free_result($request);

// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled
                FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_BOARD = $board
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY m.ID_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);

      $return = array();
      $i = 0;
      while ($row = mysql_fetch_assoc($request))
      {
         // If this isn't the first post and the post is longer than the maximum length
         if (strlen($row['body']) > $length && $i>0)
         {
           $row['body'] = substr($row['body'], 0, $length);

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

          if ($cutoff !== false)
            $row['body'] = substr($row['body'], 0, $cutoff);
          $row['body'] .= '... <br>(<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">More</a>)';
      }
      ++$i;
      $row['body'] = doUBBC($row['body'], $row['smileysEnabled']);

      censorText($row['subject']);
      censorText($row['body']);

      $return[] = array(
         'id' => $row['ID_TOPIC'],
         'icon' => '<img src="' . $settings['images_url'] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" />',
         'subject' => $row['subject'],
         'time' => timeformat($row['posterTime']),
         'timestamp' => $row['posterTime'],
         'body' => $row['body'],
         'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
         'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
         'replies' => $row['numReplies'],
         'new_comment' => '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
         'poster' => array(
             'id' => $row['ID_MEMBER'],
             'name' => $row['posterName'],
             'href' => !empty($row['ID_MEMBER']) ? $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] : '',
             'link' => !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
         ),
         'is_last' => false
    );
}
mysql_free_result($request);

if (empty($return))
    return $return;

$return[count($return) - 1]['is_last'] = true;

foreach ($return as $news)
{

// This is where you format your posts

  echo '
    <table border="0" width="100%" align="center" class="ssi_table">
    <tr><td>', $news['icon'], ' <b>', $news['subject'], '</b></td></tr>
    <tr><td>', $news['body'], '</td></tr>
    <tr><td><center><hr width="50%" /></center>
            <span class="smalltext">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '</span></td></tr>
    </table>
    <br />';
      echo '<hr width="100%" /><br />';

    if ($news['is_last'])
      echo '<center><a href="' . $scripturl . '?board=' . $board . '.0">Announcement Archives</a></center>';
}


Just to be clear as to what this does: It pulls the n most recent posts from a given board, displaying all of the first one and the beginnings of the rest, with links to the posts for those that are cut off. At the bottom, there's a link to the board so that people can read all of the previous announcements in their entirety.

Edited: I found a little problem with the "More" link having arguments with linebreaks. So I changed it to always break on a line break.

Edited again: Why is it that you never find the problems until after you show it to someone else? I think I've got it fixed now. I added a line break before the "More" link. That should fix the problem.

jarnex

I tried this, and it works well as an article, but it doens't work quite the same as the front-page block of board-news, in settings.  That one allows you to page through the entire board you select there and it also formats each article in the theme (i.e I am using Enterprise TP, and each post is topped by a blue bar etc)  Do you know how to make that block appear in an article?  That way I could feature my media files boards in articles, but still have the posting as part of my forum?

JPDeni

You might look at TPortalBlocks.template.php in your theme directory to see what the code is for printing out the block. Look for function TPortal_newsbox(). (I think that's what you want.) Or find the one that you want. They're all in that file.

jarnex


RoarinRow

JP I got this message when accessing your link

Authorization Required
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Additionally, a 401 Authorization Required error was encountered while trying to use an ErrorDocument to handle the request.

SMF 2.0 RC3
TP 1.0 beta 5-1
Wordpress 3.0

JPDeni

Sorry. I hadn't seen your post earlier.

I had to password-protect the directory. Maybe I'll make a separate one just to work out mods and stuff. I removed the link in my earlier post so others don't get confused.

Actually, I changed it, anyway. :) I was making it a whole lot more complicated than it needed to be.

Basically, I copied function ssi_boardNews from SSI.php to a php block, altered it a little bit and renamed it to function ssi_boardNews_announce. Then I added the following to the beginning of the block:

global $scripturl;

ssi_boardNews_announce($board = 20.0, $limit = 1, $start = 0, $length = null, $output_method = 'echo');
echo '<hr style="margin: 2ex 0;" width="100%" />';
ssi_boardNews_announce($board = 20.0, $limit = 4, $start = 1, $length = 300, $output_method = 'echo');
echo '<hr style="margin: 2ex 0;" width="100%" />';
echo '<div style="text-align:center"><a href="' . $scripturl . '?board=20.0">Archived Announcements</a></center>';


Works a whole lot better and is more intuitive.

The alterations were just to eliminate the reference to comments and to not print the "Read more" link if the entire post has been printed out.

This website is proudly hosted on Crocweb Cloud Website Hosting.