Hello! I have a block code which shows recent topics in a table. It only displays topic, poster and time. I would like to add board name and topic starter to the block (and maybe views/read). I have tried to make the changes for hours, but my skills aren't good enough (yet). Can anybody please help me with this? :)
The code:
// [SETUP HERE] //
$num_recent = 25; // HOW MANY RECENT TOPICS TO OUTPUT?
$include_boards = array(2); // IF ALL BOARDS null | IF SOME BOARDS array( ID1, ID2, ID3)
// code, code, code and some more code bahhh!
global $smcFunc, $scripturl, $context, $settings, $db_prefix, $user_info;
if (is_array($include_boards) || (int) $include_boards === $include_boards)
{
$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
}
elseif ($include_boards != null)
{
$output_method = $include_boards;
$include_boards = array();
}
$topics_result = $smcFunc['db_query']('', '
SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)' . (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})' : '') . '
WHERE m.approved=1' . (empty($include_boards) ? '' : '
AND b.id_board IN ({array_int:include_boards})') . '
ORDER BY t.id_last_msg DESC
LIMIT ' . $num_recent,
array(
'current_member' => $user_info['id'],
'include_boards' => empty($include_boards) ? '' : $include_boards,
)
);
$topics = array();
while ($row_topics = $smcFunc['db_fetch_assoc']($topics_result))
{
$topics[] = array(
'topic' => $row_topics['id_topic'],
'poster' => '<a style="color: ' . $row_topics['online_color'] . ';" href="' . $scripturl . '?action=profile;u=' . $row_topics['id_member_updated'] . '">' . $row_topics['poster_name'] . '</a>',
'link' => '<a title="In ' . $row_topics['name'] .'" href="' . $scripturl . '?topic=' . $row_topics['id_topic'] . '.msg' . $row_topics['id_last_msg'] . ';topicseen#new">' . $row_topics['subject'] . '</a>',
'href' => $scripturl . '?topic=' . $row_topics['id_topic'] . '.msg' . $row_topics['id_last_msg'] . ';topicseen#new',
'time' => timeformat($row_topics['poster_time']),
'new' => !empty($row_topics['is_read'])
);
}
$smcFunc['db_free_result']($topics_result);
echo '
<div class="tabsmenucontent" style="padding: 2px">
<table border="0" width="100%" cellspacing="1" cellpadding="2" class="bordercolor">
<tr class="titlebg">
<td valign="middle">Topic</td>
<td valign="middle">Poster</td>
<td valign="middle">Time</td>
<td valign="middle"></td>
</tr>';
foreach ($topics as $topic)
{
echo '
<tr>
<td class="windowbg" valign="middle">', $topic['link'];
// new log! What a headache!
if (!$topic['new'] && $context['user']['is_logged'])
echo '
<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" /></a>';
echo '
</td>
<td class="windowbg2" valign="middle">', $topic['poster'], '</td>
<td class="windowbg2" valign="middle">', $topic['time'], '</td>
<td class="windowbg2" valign="middle">';
if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
echo '
<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="Last Post" title="Last Post" border="0" style="float: right;" /></a>';
}
echo '
</td>
</tr>
</table>
</div>';
Why aren't you using SSI for that?
It basically IS one of the SSI functions...
Thanks a lot for the suggestion! If I use this code: <?php ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boards = null, $output_method = 'echo'); ?> Then only get board, topic and date. Am I using wrong SSI-code? And it doesn't output a table. I think the code in my first post makes a nice table, it should include board and topic starter.
The SSI worked nice, but it only outputs results from the last week. Therefore I want to use the code mentioned in my first post. I try to add board name and views/posts to the block-code in the first post. I have understood that it's difficult to add the topic starter. Any suggestions?
If you're referring to the code in the other topic, firstly did you actually try changing the number of items specified? Secondly, did you notice the specific comment made with reference to performance?
Lainaus käyttäjältä: Arantor - marraskuu 19, 2013, 06:52:06 IP
If you're referring to the code in the other topic, firstly did you actually try changing the number of items specified? Secondly, did you notice the specific comment made with reference to performance?
Yes and yes.
I have tried different ways to make a suitable code for recent topics (therefore two posts - or three - sorry for that).
Now I have landed on this SSI-code:
$topics = ssi_recentTopics(10, null, null, 'array');
echo '<table border="0" width="100%">
<tr>
<td bgcolor="#0078A7"><font color="#FFFFFF"><b>Topic</b></th>
<td bgcolor="#0078A7"><font color="#FFFFFF"><b>new.gif here</b></th>
<td bgcolor="#0078A7"><font color="#FFFFFF"><b>Board</b></th>
<td bgcolor="#0078A7"><font color="#FFFFFF"><b>By</b></th>
<td bgcolor="#0078A7"><font color="#FFFFFF"><b>Read/posts</b></th>
<td bgcolor="#0078A7"><font color="#FFFFFF"><b>Date</b></th>
</tr>';
foreach ($topics as $this_topic)
echo '<tr><td>', $this_topic['link'], '</td>
<td>', $this_topic['board']['link'], '</td>
<td>', $this_topic['poster']['link'], '</td>
<td>', $this_topic['views'], '/', $this_topic['replies'], '</td>
<td>', $this_topic['time'], '</td></tr>';
echo '
</table>';
I managed to grab posts older than 7 days in the SSI.php file, and the only thing missing now is the new.gif icon.