# Adding number of posts in each category

**URL:** https://meta.discourse.org/t/adding-number-of-posts-in-each-category/277350
**Category:** Development
**Tags:** custom-header-links
**Created:** [August 31, 2023, 1:11pm UTC](https://meta.discourse.org/t/adding-number-of-posts-in-each-category/277350 "2023-08-31T13:11:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![OsaIsacson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osaisacson/32/263464_2.png) [@OsaIsacson](https://meta.discourse.org/u/OsaIsacson)
#### Post date: [August 31, 2023, 1:11pm UTC](https://meta.discourse.org/t/adding-number-of-posts-in-each-category/277350/1 "2023-08-31T13:11:25Z")

</div>

I am using [Custom Header Links](https://github.com/discourse/discourse-custom-header-links) and wonder if it is possible to in it pass number of posts.

Does there exist a shorthand that grabs the current nr of posts for a specific category?

Like so:

Current

 ![Screenshot 2023-08-31 at 15.06.56](https://global.discourse-cdn.com/meta/original/4X/f/4/d/f4d1caa773aefa89d159b425cd488b11115a6269.jpeg)

Wanted

 ![Screenshot 2023-08-31 at 15.09.04](https://global.discourse-cdn.com/meta/original/4X/2/5/2/2529c80da823461acef3e0375683d446484d619e.jpeg)

---

<div class="post-metadata">

### Author: ![OsaIsacson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osaisacson/32/263464_2.png) [@OsaIsacson](https://meta.discourse.org/u/OsaIsacson)
#### Post date: [September 27, 2023, 7:57am UTC](https://meta.discourse.org/t/adding-number-of-posts-in-each-category/277350/2 "2023-09-27T07:57:17Z")

</div>

Still looking to find out how to pass number of posts - by way of example we can see it being done in the docs view:

 ![Screenshot 2023-09-27 at 09.53.53](https://global.discourse-cdn.com/meta/original/4X/1/2/6/126fa53e0e112f78e803cd812e095ea686dd9f93.jpeg)  
…it does not need to be in the custom header links. I also have a custom injected section on the start page that might be easier to pass it to.

Just wondering which code was used to catch them in the above screenshot or if there is (hope against hope) a shorthand?

---

<div class="post-metadata">

### Author: ![Rhababo](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@Rhababo](https://meta.discourse.org/u/Rhababo)
#### Post date: [September 29, 2023, 3:56am UTC](https://meta.discourse.org/t/adding-number-of-posts-in-each-category/277350/3 "2023-09-29T03:56:08Z")

</div>

To clarify: You want the number of posts per category, not the number of topics per category?

Either way I can say that it certainly is possible.

I am personally quite new to ember.js so I can only offer this in theory at the moment.

```plaintext
import Component from "@glimmer/component";
import Service, { inject as service } from "@ember/service";
import { action } from "@ember/object";

export default class CategoryStats extends Component {
  @service site
 
  categoryId = **input category id number** ;
  postcount = this.site.categories[this.categoryId-1].post_count;

}

```

Because each category does keep track of the total number of posts, and the site keeps track of each category in a categories array, you could add an ember component like the one above and then output the {{postcount}} to the template from the Custom Header Links, or wherever else you’d like.

However, I am currently too dumb to know how pass in that categoryId value as an input, so I will have to punt this to someone smarter or more experienced.

---

<div class="post-metadata">

### Author: ![Rhababo](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@Rhababo](https://meta.discourse.org/u/Rhababo)
#### Post date: [September 29, 2023, 5:04pm UTC](https://meta.discourse.org/t/adding-number-of-posts-in-each-category/277350/4 "2023-09-29T17:04:11Z")

</div>

After a night’s sleep, I realized that I could modify the original Custom Header Links theme component to let the categoryId be passed through the app settings.

> **[GitHub - Rhababo/discourse-category-header-links](https://github.com/Rhababo/discourse-category-header-links)**
>
> Contribute to Rhababo/discourse-category-header-links development by creating an account on GitHub.

I can’t promise this will work for you, but it functions on my test server. I do make the assumption that the category id’s match with their location in the site’s category id array. I’d recommend making your own copy of this and tweaking it to fit your needs.

---

<div class="post-metadata">

### Author: ![OsaIsacson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/osaisacson/32/263464_2.png) [@OsaIsacson](https://meta.discourse.org/u/OsaIsacson)
#### Post date: [October 26, 2023, 9:40am UTC](https://meta.discourse.org/t/adding-number-of-posts-in-each-category/277350/5 "2023-10-26T09:40:40Z")

</div>

GLORIOUS BEING! Thank you. This solved everything. Looking good: [https://bygg.boihop.co/](https://bygg.boihop.co/)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [November 25, 2023, 9:41am UTC](https://meta.discourse.org/t/adding-number-of-posts-in-each-category/277350/6 "2023-11-25T09:41:10Z")

</div>

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