# How to show user total post count beside name

**URL:** https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718
**Category:** Development
**Created:** [December 6, 2023, 1:15pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718 "2023-12-06T13:15:25Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [December 6, 2023, 1:15pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/1 "2023-12-06T13:15:25Z")

</div>

Hi everyone, this is my first post here. I’m wondering how the [Blizzard forum](https://us.forums.blizzard.com/en/blizzard/t/helltide-doesnt-work-not-getting-exp/48411) shows the total post count of a user besides their name.

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/6/3/463e72606ecc438bce6c5634662645513aadb22c.jpeg)  
I’ve implemented something similar in my forum by using the Discourse API system like below  
 ![image](https://global.discourse-cdn.com/meta/original/4X/4/f/9/4f952127729ce2c5d7a60f9348e025585b011af8.png)  
But I believe there are better ways of doing this. I’m also planning to show the user badge etc. Can anyone help me with this? Thank you.

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [December 6, 2023, 1:27pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/2 "2023-12-06T13:27:34Z")

</div>

I’m wondering if there’s any template/shortcode system exist.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [December 6, 2023, 1:31pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/3 "2023-12-06T13:31:04Z")

</div>

Hi!

If you are using the API, I believe this is the correct way.

Could you please share your code with us? We can provide suggestions for improvement, if necessary. 🙂

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [December 6, 2023, 1:34pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/4 "2023-12-06T13:34:39Z")

</div>

Sure

```plaintext
<script type="text/discourse-plugin" version="0.1">
  api.onPageChange(() => {
    // Check if an element with ID 'topic' exists
    if ($('#topic').length > 0) {
      // If 'topic' element exists, find 'data-user-id' attribute
      var userId = $('#topic article').data('user-id');

      // Check if 'data-user-id' attribute exists
      if (userId !== undefined) {
        // Make an API request to get user info
        apiReq(`admin/users/${userId}.json`, 'GET')
          .then(data => {
            // Handle the response data
            console.log('User post count:', data.post_count);

            // Check if the user has a value in user_fields["1"]
            if (data.user_fields && data.user_fields["1"]) {
              // Display the user field inside the first 'names' div
              displayUserField(data.user_fields["1"]);
            }

            // Display the post count inside the first 'names' div
            displayPostCount(data.post_count);
          })
          .catch(error => {
            // Handle errors
            console.error('API request error:', error);
          });
      } else {
        console.log('No data-user-id attribute found');
      }
    } else {
      console.log('No element with ID "topic" found');
    }
  });

  // Function to display the user field inside the first 'names' div
  function displayUserField(userFieldValue) {
    // Find the first 'names' div
    var firstNamesDiv = $('.names:first');

    // Create a span element with classes 'user-title'
    var userFieldSpan = $('<span></span>').addClass('user-title');
    userFieldSpan.text(userFieldValue);

    // Append the span element to the first 'names' div
    firstNamesDiv.append(userFieldSpan);
  }

  // Function to display the post count inside the first 'names' div
  function displayPostCount(postCount) {
    // Find the first 'names' div
    var firstNamesDiv = $('.names:first');

    // Create a span element with classes 'user-title'
    var postCountSpan = $('<span></span>').addClass('user-title');
    postCountSpan.text(postCount + ' posts');

    // Append the post count span element to the first 'names' div
    firstNamesDiv.append(postCountSpan);
  }

</script>

```

I have the apiReq function on another component

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [December 6, 2023, 1:36pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/5 "2023-12-06T13:36:57Z")

</div>

In Blizzard, they are showing the post count beside commenters which I couldn’t achieve.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [December 6, 2023, 1:51pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/6 "2023-12-06T13:51:17Z")

</div>

I see, you partially use the API. You can definitively improve this code. Give me some minutes, and I will back to you.

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [December 6, 2023, 2:00pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/7 "2023-12-06T14:00:30Z")

</div>

Sounds good. I’m new in Discourse that’s why I know very little about it.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [December 7, 2023, 2:46am UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/8 "2023-12-07T02:46:49Z")

</div>

I had to make a plugin instead.

In order to obtain the `post_count` value when viewing a post or a user’s card, it is necessary to serialize the data to include this field. This can only be achieved with the help of a plugin and relying on requests per user is not a realistic solution.

Give it a try. The JS part is in `assets` if you want to take a look.  
One specific thing you may have missed in using the API is the ability to customize via [outlets](https://meta.discourse.org/t/using-plugin-outlet-connectors-from-a-theme-or-plugin/32727).

Let me know if you want more options.  
I don’t know if I should release this plugin as it’s small, but here we go anyway:  
[https://github.com/Arkshine/discourse-user-post-count](https://github.com/Arkshine/discourse-user-post-count)

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [December 7, 2023, 3:38am UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/9 "2023-12-07T03:38:19Z")

</div>

Thank you so much for the effort. I’ll try it.  
My actual plan was to achieve the following feature

1. Show post count of user in post and comments next to avatar.
2. Assign a default title to all the members of a group (ex: Admin)
3. Show trust level beside avatar
4. Show badge beside avatar.
5. Show a user\_field value beside avatar.  
And options are changeable by admin.  
I also planned to hyperlink the post count so others can click and see the list of posts.

Although, it’s a small plugin, I believe it worth publishing. You may consider to add new features as suggested.  
Thank you

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [December 18, 2023, 5:00pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/10 "2023-12-18T17:00:18Z")

</div>

I installed the plugin but it doesn’t work.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [December 18, 2023, 5:06pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/11 "2023-12-18T17:06:14Z")

</div>

I tested it again, and it works fine on my side.

Is the plugin enabled?

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/c/c/7ccc8ba82a4dee56ccc1a822244e1e221f84dea9.png)

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [December 20, 2023, 5:21pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/12 "2023-12-20T17:21:01Z")

</div>

It’s working now. Thank you.

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [January 2, 2024, 12:38pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/13 "2024-01-02T12:38:01Z")

</div>

Sorry to bother you again. After using for a while, I noticed that it doesn’t includes topics. As far I know a topic is also a post.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [January 2, 2024, 2:02pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/14 "2024-01-02T14:02:36Z")

</div>

_Topics created_ is another stat. Do you want to add this count to the posts count or add a new text so you would have “_topics: xx, posts: yy_”?

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [January 2, 2024, 2:27pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/15 "2024-01-02T14:27:56Z")

</div>

I actually trying to gain something like postCount + TopicCount  
simply want to count topics as post.  
Also trying to show that after user title (if have any). I tried to modify the plugin code (after forking) but no luck so far.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [January 3, 2024, 3:35am UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/16 "2024-01-03T03:35:51Z")

</div>

I updated the plugin; let me know if it works for you.

---

<div class="post-metadata">

### Author: ![Farhan\_Hossen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/farhan_hossen/32/344620_2.png) [@Farhan\_Hossen](https://meta.discourse.org/u/Farhan_Hossen)
#### Post date: [January 7, 2024, 12:37pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/17 "2024-01-07T12:37:33Z")

</div>

Thank you so much. It worked.

---

<div class="post-metadata">

### Author: ![David\_Ghost](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@David\_Ghost](https://meta.discourse.org/u/David_Ghost)
#### Post date: [October 3, 2024, 2:46pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/18 "2024-10-03T14:46:23Z")

</div>

> [@Arkshine](#):
>
> I updated the plugin; let me know if it works for you

Looks so cool. Is it possible to add the total reactions + FA icons too?

---

<div class="post-metadata">

### Author: ![David\_Ghost](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@David\_Ghost](https://meta.discourse.org/u/David_Ghost)
#### Post date: [February 14, 2025, 9:52pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/19 "2025-02-14T21:52:21Z")

</div>

I cant edit, so, I just installed and tested the plugin, and it’s working very well. Except on mobile, where the total number of posts is being displayed on the left side of the name. ☹

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [February 14, 2025, 10:23pm UTC](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718/20 "2025-02-14T22:23:40Z")

</div>

@David_Ghost

You can fix it with some CSS:

```css
.names.trigger-user-card > div:has(.user-post-user__container) {
    order: 2;
}

```

[Next page](https://meta.discourse.org/t/how-to-show-user-total-post-count-beside-name/287718.md?page=2)
