Please or Register to create posts and topics.

Get First Topics Post In The Last Topics Widget

Hello, Thanks for your great plugin.

Im trying to show latest topics from a forum and their summary in my home page.

I used i widget shortcode and changed some styles from the widgets php and its working well.

My problem is that excerpt shows the latest post but i wanna see the first post in topic, i think i should change something in below query but i dont know how to do it. what should i do to change this? thanks.

$elements = $this->asgarosforum->db->get_results("SELECT p.id, p.text, p.date, p.parent_id, p.author_id, t.name, (SELECT COUNT(*) FROM {$this->asgarosforum->tables->posts} WHERE parent_id = p.parent_id) AS post_counter FROM {$this->asgarosforum->tables->posts} AS p LEFT JOIN {$this->asgarosforum->tables->topics} AS t ON (t.id = p.parent_id) WHERE p.forum_id IN({$available_forums}) AND p.id IN (SELECT MAX(p_inner.id) FROM {$this->asgarosforum->tables->posts} AS p_inner GROUP BY p_inner.parent_id) AND t.approved = 1 ORDER BY t.id DESC LIMIT {$number};");

Uploaded files:
  • asgaros.png

Hey @alireza,

yes this query get’s all the posts for the widget. Please be aware that all changes on the plugin files will be deleted with every update of Asgaros Forum. So you have to do all this changes again after every update. This also applies to all changes to the CSS files. To get this changes permanently you should write a own plugin to create a custom widget.

But back to your question. To get the first post of the last topic you have to  change MAX(p_inner.id) to MIN(p_inner.id) :

$elements = $this->asgarosforum->db->get_results("SELECT p.id, p.text, p.date, p.parent_id, p.author_id, t.name, (SELECT COUNT(*) FROM {$this->asgarosforum->tables->posts} WHERE parent_id = p.parent_id) AS post_counter FROM {$this->asgarosforum->tables->posts} AS p LEFT JOIN {$this->asgarosforum->tables->topics} AS t ON (t.id = p.parent_id) WHERE p.forum_id IN({$available_forums}) AND p.id IN (SELECT MIN(p_inner.id) FROM {$this->asgarosforum->tables->posts} AS p_inner GROUP BY p_inner.parent_id) AND t.approved = 1 ORDER BY t.id DESC LIMIT {$number};");

 

Asgaros has reacted to this post.
Asgaros
Need professional help with Asgaros Forum? Book an appointment with us at domra Web Solutions for setup and customization services. Learn more about our Toolbox for Asgaros Forum plugin to enhance your forum experience.

@qualmy91

thanks bro thats working well! 😁