# Add like\_count column to topic list

**URL:** https://meta.discourse.org/t/add-like-count-column-to-topic-list/43376
**Category:** Development
**Created:** [4월 28, 2016, 11:12오전 UTC](https://meta.discourse.org/t/add-like-count-column-to-topic-list/43376 "2016-04-28T11:12:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Anthony\_Hopkins](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/anthony_hopkins/32/121811_2.png) [@Anthony\_Hopkins](https://meta.discourse.org/u/Anthony_Hopkins)
#### Post date: [4월 28, 2016, 11:12오전 UTC](https://meta.discourse.org/t/add-like-count-column-to-topic-list/43376/1 "2016-04-28T11:12:36Z")

</div>

I need to display `like_count` to topic list.

I know I can add `TopicViewSerializer.attributes_from_topic(:like_count)` to my plugin and use outlet “topic-list-tags”

But perhaps there is a better way.  
Any idea how to turn on this line?  
[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs#L25](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs#L25)

It would be perfect if there is an option to “Like topic” directly from topic list.

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [5월 3, 2016, 9:39오전 UTC](https://meta.discourse.org/t/add-like-count-column-to-topic-list/43376/2 "2016-05-03T09:39:51Z")

</div>

> [@Anthony\_Hopkins](#):
>
> It would be perfect if there is an option to “Like topic” directly from topic list.

That’s not very feasible yet. Might change in the future. Explained here:

> [@Wanted: Discourse Hacker News Plugin](https://meta.discourse.org/t/wanted-discourse-hacker-news-plugin/37620/14):
>
> Hey team! I want to add some information to this thread since I just made an attempt to build a piece of this. Creating the link topic seems to be covered by this plugin: [GitHub - danskdynamit/discourse-links-category](https://github.com/danskdynamit/discourse-links-category) What I attempted was the upvote plugin. I found that without a significant amount of duplication of code and monkey-patching, it’s not possible to break out the like button and reuse it elsewhere. In order to add this like/vote button on the topic list, that’s exactly what you wo…

---

<div class="post-metadata">

### Author: ![Anthony\_Hopkins](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/anthony_hopkins/32/121811_2.png) [@Anthony\_Hopkins](https://meta.discourse.org/u/Anthony_Hopkins)
#### Post date: [5월 6, 2016, 7:12오전 UTC](https://meta.discourse.org/t/add-like-count-column-to-topic-list/43376/3 "2016-05-06T07:12:27Z")

</div>

Thank you,

After many many tries I prepared working extension of ‘discourse/views/topic-list-item’ and `click(e)` event:

```plaintext
if (target.hasClass('like-count') || target.parents('.like-count').length > 0) {
  const topic = this.get('topic');
  Discourse.ajax(`/posts/by_number/${topic.id}/1`).then(result => {
    const post = Post.create(result);
    if(post.user_id == Discourse.User.current().id){
      bootbox.alert(I18n.t('cant_thumb_up'))
      return false;
    }
    post.get('likeAction').togglePromise(post).then(resultLike => {
      if(resultLike.acted) {
        target.closest('.like-count').toggleClass('liked');
        topic.like_count = topic.like_count+1;
        target.closest('.like-count').find('span').text(topic.like_count);
      }else{
        target.closest('.like-count').removeClass('liked');
        topic.like_count = topic.like_count-1;
        target.closest('.like-count').find('span').text(topic.like_count);
      }
    })
  });
  return false;
}

```

+ CSS + view extension.

I know it’s not perfect solution but Base works very well.
