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.
Also, I wouldn't mind knowing if their is a method of making the table collapsible?
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.
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).
How many characters do you want to shorten it to?
Probably 50 or so.
Easiest way of doing this is in Sources/BoardIndex.php
// 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']);
}
// 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);
}
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>';
The changes I refer to are in a different file entirely.
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.
Errors in the error log?
Nothing.
So are all the titles shorter than 50 characters?
No, I even tried lowering it to a 20 character limit and nothing. I cleared my browser cache as well.
And the file definitely saved on the server?
Yeah.
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.
Ah, I forgot about that.
Instead, you'll have to edit Recent.php to change it.
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>'
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'] . '">' . shorten_subject($row['subject'], 50) . '</a>'
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?
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)