SimplePortal

Customization => Custom Coding => Topic started by: grafitus on March 07, 2011, 11:32:53 AM

Title: [Block] The last post of a topic
Post by: grafitus on March 07, 2011, 11:32:53 AM
Question: How can I show the last post of selected a topic?
(Maybe useful for someone :0)

Create a new PHP block. And copy the below to body:
Code: [Select]
global $smcFunc, $scripturl;

// Topic ID
$topic = 2;

$request = $smcFunc['db_query']('', '
SELECT t.id_topic, m.subject, m.body
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
WHERE t.id_topic = {int:topic}
LIMIT 1',
array(
'topic' => $topic,
)
);
list($id_topic, $subject, $body) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

$body = parse_bbc($body);

echo '
<strong><a href="', $scripturl, '?topic=', $id_topic, '.0">', $subject, '</a></strong>
<p>', $body, '</p>';
SimplePortal 2.3.8 © 2008-2024, SimplePortal