Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: livingfree on December 04, 2009, 02:24:53 PM

Title: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 02:24:53 PM
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.
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 02:47:24 PM
Also, I wouldn't mind knowing if their is a method of making the table collapsible?
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 04, 2009, 08:46:26 PM
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.
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 08:56:12 PM
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).
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 04, 2009, 08:59:08 PM
How many characters do you want to shorten it to?
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 09:01:09 PM
Probably 50 or so.
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 04, 2009, 09:16:00 PM
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);
}
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 09:30:51 PM
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>';
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 04, 2009, 09:33:12 PM
The changes I refer to are in a different file entirely.
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 09:42:37 PM
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.
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 04, 2009, 09:43:02 PM
Errors in the error log?
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 09:46:54 PM
Nothing.
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 04, 2009, 09:48:47 PM
So are all the titles shorter than 50 characters?
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 09:50:20 PM
No, I even tried lowering it to a 20 character limit and nothing. I cleared my browser cache as well.
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 04, 2009, 09:51:04 PM
And the file definitely saved on the server?
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 09:57:25 PM
Yeah.
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 04, 2009, 10:18:33 PM
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.
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 05, 2009, 04:38:48 AM
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>'
Title: Re: Limit title length in recent posts?
Post by: livingfree on December 06, 2009, 06:51:42 PM
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?
Title: Re: Limit title length in recent posts?
Post by: Arantor on December 07, 2009, 01:10:10 AM
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)