`showOpLikes` doesn't work right away, but after clicking back and forth

Hello. I’d like to have like counts of original posts on the main page. I followed instuctions from this post: Display Like Counts on Home Page Topic List

I added the following code with showOpLikes, but I have issues with it. Somehow it doesn’t show original post like counts right away. I only does this after click sort by likes and back to latest without sorting.

Interestingly, showLikes doesn’t have this issue.

<script>
var TopicListComponent = require('discourse/components/topic-list').default;
TopicListComponent.reopen({
    showOpLikes: true
});
</script>

Here is a screenshot before clicking on sort by likes and going to latest:


And this is after:

2 Likes

I believe showOpLikes should only work when sorting by OP likes by visiting a URL like https://meta.discourse.org/latest?order=op_likes, otherwise the op_like_count isn’t included (showLikes, should work… but that’s the total for the entire topic).

You can see this in action by viewing https://meta.discourse.org/latest.json and https://meta.discourse.org/latest.json?order=op_likesop_like_count is only available in that second link.

5 Likes

Yeah, but is there any logic behind this, or is it a bug?

1 Like

It’s intentionally built that way, but I’m not sure the exact reason. I suspect it’s data we don’t want to carry around on every page load.

We’ve also generally considered the total likes within a topic to be a better measurement of discussion quality than OP alone.

4 Likes

Well, it depends on the goals of the community I guess. Our posts represent math questions and problems, so we’d like to see the most liked ones, and I’m not sure including likes given to answers should be considered. Hm. I don’t know.

2 Likes

I believe that you need to add some javascript to add OP likes to the serializer. If you search “add to serializer” (perhaps without spaces) you should find some examples.

3 Likes

Well, I’ve changed it back to just showLikes, but thanks for the suggestion, I’ll maybe try this later.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.