Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Navigation

Output the first post of the topic

Last updated on 4 years ago
Posted 4 years ago
Hello! Please help me bring the first post of the topic to the forum_threads_list_panel panel.

On the main page of the site where this panel is enabled, and in it I want to make the first post of the topic show under the name of each topic
C
ChanSuper Admin
Posted 4 years ago
Give me the HTML layout format of your desired output or you want just the SQL? For the earlier, just make a screenshot of where is what with marker pen and attach in your response. I'll help you if I know what to do.
Edited by Chan on 18-05-2022 12:31, 4 years ago
Posted 4 years ago
php-fusion 8.00.100
file: /infusions/forum_threads_list_panel/forum_threads_list_panel.php

linkme.ufanet.ru/images/b84ceb0bb336d7b3c5a0b5ceb2069e8a.jpg


What I highlighted in red, it is necessary to make the conclusion of the first post of this topic there

Please
C
ChanSuper Admin
Posted 4 years ago
Sorry for the late reply.

There are 2 things you need to change to achieve that.

1. This is the column output, see that $data['forum_name'] you need to swap it out with the text.

https://github.com/PHPFusion/PHPFusion/blob/Tesseract/infusions/forum_threads_list_panel/forum_threads_list_panel.php#L85


So at the last bit, Lets change
trimlink($data['thread_subject'], 30)."</a><br />n".$data['forum_name']."
to
trimlink($data['thread_subject'], 30)."</a><br />n".$data['first_post_text']."


2. Next, this is the SQL query bit that we need to alter to output a new data column.

https://github.com/PHPFusion/PHPFusion/blob/Tesseract/infusions/forum_threads_list_panel/forum_threads_list_panel.php#L43-L54

Since we need the new first_post_text, we need to redo this query a bit.

Change:

$result = dbquery(
 "SELECT   f.forum_id, f.forum_cat, f.forum_name, f.forum_description, f.forum_moderators, f.forum_lastpost, f.forum_postcount,
 f.forum_threadcount, f.forum_lastuser, f.forum_access, f2.forum_name AS forum_cat_name, f2.forum_description AS forum_cat_description,
 t.thread_id, t.thread_lastpost, t.thread_lastpostid, t.thread_subject, t.thread_postcount, t.thread_views, t.thread_lastuser, t.thread_poll,
 u.user_id, u.user_name, u.user_status, u.user_avatar
 FROM ".DB_FORUMS." f
 LEFT JOIN ".DB_FORUMS." f2 ON f.forum_cat = f2.forum_id
 LEFT JOIN ".DB_THREADS." t ON f.forum_id = t.forum_id AND f.forum_lastpost=t.thread_lastpost
 LEFT JOIN ".DB_USERS." u ON f.forum_lastuser = u.user_id
 ".(multilang_table("FO") ? "WHERE f2.forum_language='".LANGUAGE."' AND" : "WHERE")." ".groupaccess('f.forum_access')." AND f.forum_cat!='0' AND t.thread_lastpost >= ".$timeframe." AND t.thread_hidden='0'
 GROUP BY thread_id ORDER BY t.thread_lastpost LIMIT ".$settings['numofthreads'].""
);


$result = dbquery(
 "SELECT   f.forum_id, f.forum_cat, f.forum_name, f.forum_description, f.forum_moderators, f.forum_lastpost, f.forum_postcount,
 f.forum_threadcount, f.forum_lastuser, f.forum_access, f2.forum_name AS forum_cat_name, f2.forum_description AS forum_cat_description,
 t.thread_id, t.thread_lastpost, t.thread_lastpostid, t.thread_subject, t.thread_postcount, t.thread_views, t.thread_lastuser, t.thread_poll,
 u.user_id, u.user_name, u.user_status, u.user_avatar,
 (SELECT post_message FROM ".DB_POSTS." WHERE thread_id=t.thread_id ORDER BY post_id ASC LIMIT 1) AS first_post_text
 FROM ".DB_FORUMS." f
 LEFT JOIN ".DB_FORUMS." f2 ON f.forum_cat = f2.forum_id
 LEFT JOIN ".DB_THREADS." t ON f.forum_id = t.forum_id AND f.forum_lastpost=t.thread_lastpost
 LEFT JOIN ".DB_USERS." u ON f.forum_lastuser = u.user_id
 ".(multilang_table("FO") ? "WHERE f2.forum_language='".LANGUAGE."' AND" : "WHERE")." ".groupaccess('f.forum_access')." AND f.forum_cat!='0' AND t.thread_lastpost >= ".$timeframe." AND t.thread_hidden='0'
 GROUP BY thread_id ORDER BY t.thread_lastpost LIMIT ".$settings['numofthreads'].""
);


Let me know if it works for you. Screenshot of my test for the SQL.

And the text might be very long, so I suggest you to trim it, using trimlink function, or use CSS to line wrap it in 1 line.
As forum text might contain bbcode, you might want to use the parseubb function.
Chan attached the following image:
Image not found
Posted 4 years ago
Chan, Thank you very much, it works as I wanted!
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
You cannot set up a bounty in this discussion thread.
Moderator: Support Team
Users who participated in discussion: Chan, Alex-newcode-NSK