# 在顶部菜单添加未解决按钮，使用自定义HTML

**URL:** https://meta.discourse.org/t/add-unsolved-button-to-top-menu-using-custom-html/59758
**Category:** Development
**Tags:** how-to
**Created:** [2017年三月23日 11:50 UTC](https://meta.discourse.org/t/add-unsolved-button-to-top-menu-using-custom-html/59758 "2017-03-23T11:50:18Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![Kahi](https://avatars.discourse-cdn.com/v4/letter/k/e47774/32.png) [@Kahi](https://meta.discourse.org/u/Kahi)
#### Post date: [2017年十月16日 13:58 UTC](https://meta.discourse.org/t/add-unsolved-button-to-top-menu-using-custom-html/59758/5 "2017-10-16T13:58:28Z")

</div>

> [@david](#):
>
> That works great, if you want to only display the buttons on certain categories then you can do some fairly simple logic to check the category name. I also filter out “closed” topics for my “unsolved” button.
> 
> This is what I use:
> 
> ```plaintext
> <script>
> Discourse.ExternalNavItem = Discourse.NavItem.extend({
> href : function() {
> return this.get('href');
> }.property('href'),
> });
> 
> I18n.translations.en.js.filters.Completed = { title: "Completed", help: "Topics that have been marked as solved" };
> I18n.translations.en.js.filters.Outstanding = { title: "Outstanding", help: "Topics that are not yet marked as solved" };
> 
> Discourse.NavItem.reopenClass({
> buildList : function(category, args) {
> var list = this._super(category, args);
> if(!category) {
> //Don't display anything
> }else if(category.slug==='support') {
> list.push(Discourse.NavItem.create({href: '/c/support?solved=yes', name: "Completed"}));
> list.push(Discourse.NavItem.create({href: '/c/support?solved=no&status=open', name: "Outstanding"}));
> }else if(category.slug==='jobs') {
> list.push(Discourse.NavItem.create({href: '/c/jobs?solved=yes', name: "Completed"}));
> list.push(Discourse.NavItem.create({href: '/c/jobs?solved=no&status=open', name: "Outstanding"}));
> }
> return list;
> }
> });
> </script>
> 
> ```

> [@Chanka\_Dod](#):
>
> I encountered that this is not working if sub categories are added. Try the following block if you add sub categories.
> 
> if(!category) {  
> list.push(Discourse.ExternalNavItem.create({href: ‘/latest?solved=no’, name: ‘unresolved’}));  
> } else {  
> if(!category.parentCategory) {  
> list.push(Discourse.ExternalNavItem.create({href: ‘/c/’+category.slug+‘?solved=no’, name: ‘unresolved’}));  
> } else {  
> list.push(Discourse.ExternalNavItem.create({href: ‘/c/’+category.parentCategory.slug+‘/’+category.slug+‘?solved=no’, name: ‘unresolved’}));  
> }
> 
> ```
> }
> 
> ```
> 
> Cheers

I’m having a little issue with combining those two. What should I have if I want both only a certain particular category and subcategory to show Solved/Unsolved?

---

_[View the full topic](https://meta.discourse.org/t/add-unsolved-button-to-top-menu-using-custom-html/59758)._
