XF 2.1 Post Likes List

betforumu

Member
Hello guys, I just wanted to know is there any setting or add-on that I can get list of likes given to post which I published.

For example there is a thread that I've opened: "Post Likes List".
Someone liked it and there are 50 likes.
I want to get list of who liked thread. (username1, username2, username3, betforumu and goes on...)

If I tried to copy/paste all of them, it copies all of date etc together. I hope I've told what I mean. Thanks for your help.
 
That would require editing the template to remove all other data, or some form of custom development.
I made it with css but it's not useful.

"
.listInline--bullet {display:none;}
.contentRow-lesser {display:none;}
.reaction--right {display:none;}

"

It works good but not useful as I said :)
 
You can simply edit /src/XF/Entity/Thread.php and add a function like the following one I created, which will return a list of usernames who reacted to the first post of the thread:


Code:
public function countReactList()
    {

               $firstPost = $this->db()->fetchRow("
                    SELECT post_id, thread_id
                    FROM xf_post
                    WHERE thread_id = ?
                    LIMIT 1
                ", $this->thread_id);

                $this->first_post_id = $firstPost['post_id'];

                $reactions = \XF::db()->fetchAll('SELECT user.username as username
                        FROM xf_reaction_content AS reacted
                        INNER JOIN xf_user AS user ON (reacted.reaction_user_id = user.user_id)
                        INNER JOIN xf_reaction AS reaction ON (reacted.reaction_id = reaction.reaction_id)
                        WHERE reacted.content_type = ? AND reacted.content_id = ? AND reaction.active = 1
                        ORDER BY reacted.reaction_date DESC', ['post', $this->first_post_id]);

                       $list = array();

                       foreach($reactions as $like){
                              $list[] = $like['username'];
                       }
              
                       $list = implode(', ', $list);
              
                       return $list;
}

And then, in thread_view you can add {{ $thread.countReactList() }} wherever you'd like to display this list, eventually restricting it to certain user groups etc..

I hope it helped.

Please note this is tested on XF2.1.x , I can't guarantee for newer versions, but the concept is quite simple to understand.
 
Back
Top Bottom