Can I make the Casper theme show all tags (not just one)?


#1

I’m altering the Casper theme to suit my site and i’d like to show every tag on each post instead of just one. I tend to have 3 or 4 tags and i’d like visitors to see all the tags instead of the one that the theme currently shows.
Hoping this is an easy one for someone to answer!
Thanks


#2

JavaScript way: Ghost has an API for that. Have a look. Get your tags then insert the Dom elements with the results. Sorry I’m on mobile but a quick search would do for their API.


#3

The handlebars way:

Casper uses the {{primary_tag}} helper in post.hbs and partials/post-card.hbs. This helper outputs just the first (aka primary) tag. Replace it with the {{tags}} helper to output all tags.

See https://docs.ghost.org/api/handlebars-themes/context/post/ for more info.

Examples of different ways of listing tags with this helper can be found on my GitHub page.


#4

Hi - thanks for the help. Unfortunately that didn’t quite work for me. I followed your instructions and it just removed any tags from the post cards and made one tag just repeat twice for each of the posts. If you’re willing to show me how the code should look i’d really appreciate it.


#5

Is it correct that in partials/post-card.hbs you replaced lines 10-13:

{{#if primary_tag}}
  <span class="post-card-tags">{{primary_tag.name}}</span>
{{/if}}

… with:

{{#if tags}}
  <span class="post-card-tags">{{tags}}</span>
{{/if}}

That should work.

Did you double check that there is more than one tag on the post in question?


#6

Thanks - that did work, but now the formatting has gone all weird. I think I might be a bit too limited in my abilities to tackle this stuff. I’d love to communicate directly if you wouldn’t mind helping out (not so keen to post the site itself here).


#7

@mijiemu Sure, send me a DM and I’ll see if I can help.


#8

Thanks - I couldn’t see a way to DM on this forum, but i’ve sent an email to the address on your website.