Limit title length in recent posts?

Started by livingfree, December 04, 2009, 02:24:53 PM

Previous topic - Next topic

livingfree

Well, I've been working on a friends SMF forum for a while now and have been able to solve every issue without a problem except this one. I'd like to be able to limit the length (characters) of the title in the recent posts table.

The problem I'm having is that if the title is too long it wraps to a second line and just looks ugly. If I limit the characters I can keep the current table width (I don't want it to be 100%) and not have to worry about it forcing the title to a second line.  Any help would be greatly appreciated.

livingfree

Also, I wouldn't mind knowing if their is a method of making the table collapsible?

Arantor

Please don't bump within 24 hours, you can always edit your post to add new details.

Might be useful if you stated what version of SMF you were working on and what theme.

livingfree

Yeah sorry it wasn't an intentional bump (at that time it was only the second topic in the forum) I just forgot to mention that. You're right I should have just edited the post.

It's 1.1.11 and I'm using the Babylon theme (though I've customized the look).

Arantor

How many characters do you want to shorten it to?

livingfree


Arantor

Easiest way of doing this is in Sources/BoardIndex.php

Code (find) Select
// We have to clean up the cached data a bit.
foreach ($context['latest_posts'] as $k => $post)
{
$context['latest_posts'][$k]['time'] = timeformat($post['raw_timestamp']);
$context['latest_posts'][$k]['timestamp'] = forum_time(true, $post['raw_timestamp']);
}


Code (replace) Select
// We have to clean up the cached data a bit.
foreach ($context['latest_posts'] as $k => $post)
{
$context['latest_posts'][$k]['time'] = timeformat($post['raw_timestamp']);
$context['latest_posts'][$k]['timestamp'] = forum_time(true, $post['raw_timestamp']);
$context['latest_posts'][$k]['subject'] = shorten_subject($post['subject'], 50);
}

livingfree

I'm sorry man, I should have mentioned that I customized it a little (I didn't realize this was what we would be needing to edit).

Here is what is the code:

// Here's where the "Info Center" starts...
   echo '
<br />
<div class="tborder"><table border="0" width="100%" cellspacing="1" cellpadding="4">
   ';

   // This is the "Recent Posts" bar.
   if (!empty($settings['number_recent_posts']))
   {
      echo '
   <tr>
      <td class="catbg" colspan="5">', $txt[214], '</td>
   </tr>

</table>
<table border="0" width="100%" cellspacing="1" cellpadding="4">

   <tr>
      <td class="windowbg" width="20" valign="middle" align="center">
         <a href="', $scripturl, '?action=recent">
            <img src="', $settings['images_url'], '/post/xx.gif" alt="', $txt[214], '" border="0" /></a>
      </td>
      <td class="windowbg2">';

      // Only show one post.
      if ($settings['number_recent_posts'] == 1)
      {
         // latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
         echo '
         <b><a href="', $scripturl, '?action=recent">', $txt[214], '</a></b>
         <div class="smalltext">
            ', $txt[234], ' "', $context['latest_post']['link'], '" ', $txt[235], ' (', $context['latest_post']['time'], ')<br />
         </div>';
      }
      // Show lots of posts.
      elseif (!empty($context['latest_posts']))
      {
         echo '
         <table width="90%" border="0" align="center">';
         /* Each post in latest_posts has:
            board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
            subject, short_subject (shortened with...), time, link, and href. */
         foreach ($context['latest_posts'] as $post)

            echo '
         <tr>

               <td style="background-color:#202020;border-color:#BBBBBB; border-style:solid; border-width:0px; text-align:center;" align="left" valign="top" nowrap="nowrap">[', $post['board']['link'], ']</td>
               <td style="background-color:#202020;border-color:#BBBBBB; border-style:solid; border-width:0px; text-align:center;" valign="top">', $post['link'], ' ', $post['time'], ' </td>
               <td style="background-color:#202020; border-color:#BBBBBB;border-style:solid; border-width:0px; text-align:center;" align="left" valign="top" nowrap="nowrap">', $txt[525], ' ', $post['poster']['link'],'</td>
            </tr>';
         echo '
         </table>';
      }
      echo '
      </td>
   </tr>';
   }

echo '
</table></div><br>';

Arantor

The changes I refer to are in a different file entirely.

livingfree

Wow, how embarrassing...my multitasking skills are lacking considerably today. Sorry if I wasted your time.
I just saw "BoardIndex" and jumped right to thinking we were talking about "BoardIndex.template.php"  O:)

That being said, it didn't seem to work.

Arantor



Arantor

So are all the titles shorter than 50 characters?

livingfree

No, I even tried lowering it to a 20 character limit and nothing. I cleared my browser cache as well.

Arantor

And the file definitely saved on the server?


livingfree

Looks like this issue lies with this line

<td style="background-color:#202020;border-color:#BBBBBB; border-style:solid; border-width:0px; text-align:center;" valign="top">', $post['link'], ' ', $post['time'], ' </td>

If I change 'link' with 'subject' it works but the title is no longer a link that takes the user to the subject.

Arantor

Ah, I forgot about that.

Instead, you'll have to edit Recent.php to change it.

Code (find) Select
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>'

Code (replace) Select
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'] . '">' . shorten_subject($row['subject'], 50) . '</a>'

livingfree

That works. Is there anyway to add '...' after any post title that gets cut off?

Also, I was still wondering if it's possible to make this section collapsible in case a user doesn't want to see the recent posts?

Arantor

I actually thought shorten_subject did that, to be honest.

Collapsible is a lot more work though; the entire info centre should be collapsible but no-one as far as I know has made the individual sections collapsible (not only do you have to add the buttons, you also have to find somewhere to put whether it should be collapsed or not, it's a big overhaul of the board index code)

Advertisement: