Log in Sign up

Only show tags with a minimum number of posts?

Is there a way to show a list of tags only if there's a minimum number of posts (say three) tagged as such?

I'm looking to do this to show a list of tags without cluttering it up too much and only showing those with a minimum number of tagged posts.

Thanks. Ray


a year ago, 6 replies   developers   tags   Edit question

I think you can use the entries.length property of each tag, along with some CSS to accomplish this, e.g.

{{#all_tags}}
<a 
  href="/tagged/{{slug}}" 
  class="total-tagged-{{entries.length}}">
  {{tag}}
</a>
{{/all_tags}}
<style>
.total-tagged-0,
.total-tagged-1,
.total-tagged-2,
.total-tagged-3 {display:none}
</style>
Answered 2 years ago · Edit answer

Worked beautifully!

Ray

Answered 2 years ago · Edit answer

How about if I want all/specific tags to be displayed instead on the home page? My template is magazine

Answered a year ago · Edit answer

If you remove the class 'clip-tags' from line 29 of the magazine template's header.html file, then replace popular_tags with all_tags you should see every tag used in the sidebar

Answered a year ago · Edit answer

Thanks! What if I have six tags but I want, say, 4 of them to be displayed instead

Answered a year ago · Edit answer

I'd just remove the template logic and simply hard-code the tags you'd like in the menu, e.g.

<div class="mt5 mb5">
  <a href="/tagged/apple"  class="no-underline no-wrap db f3 fw3 black-50">Apple</a>
  <a href="/tagged/banana"  class="no-underline no-wrap db f3 fw3 black-50">Banana</a>
  ...
</div>
Answered a year ago · Edit answer