Is there a way to fetch thread first post message from thread list without generating a ton of queries?
I add t.firstpost it returns the first post pid.
But if hook to posts to get the message from pid that will generate 1 query per thread.
Any other solutions?
I seem to get it going but it fetches the last post I wanna first?
SOLVED!!!
Can you please share what you have done?
In forumdisplay.php find:
// Start Getting Threads
$query = $db->query("
SELECT t.*, {$ratingadd}t.username AS threadusername, u.username
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
WHERE t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2 $prefixsql2
ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2
LIMIT $start, $perpage
");
Replace with:
// Start Getting Threads
$query = $db->query("
SELECT t.*, {$ratingadd}t.username AS threadusername, u.username, u.avatar, p.pid, p.message, p.tid
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
LEFT JOIN ".TABLE_PREFIX."posts p ON (p.tid=t.tid)
WHERE t.firstpost=p.pid AND t.fid='$fid' $tuseronly $tvisibleonly $datecutsql2
ORDER BY t.sticky DESC, {$t}{$sortfield} $sortordernow $sortfield2
LIMIT $start, $perpage
");
Then find:
$threadcache[$thread['tid']] = $thread;
Above add some similar:
$firstpost = $thread['message'];
Use
$firstpost in
forumdisplay_thread template
OK, this is useful, thanks :-)