As we have used it multiple times in our projects and some people have enquired about it, I want to share a re-usable solution for creating a comma separated list of terms.
This will work well with either a Repeater or Taxonomy Terms block.
Pre-requisites: You will already have either added an ACF Repeater field or associated a taxonomy containing appropriate terms to the post type you want to display it for.
Steps:
- In your query or template, add a Repeater block or Taxonomy Terms block.
- With this block selected, add a global class to it called
delimited-list
- With the
delimited-list
class selected, click on the Advanced tab and add the following to the SCSS field:
.globalclass>div, .globalclass>span {
display: inline-block;
}
.globalclass>div>p::after, .globalclass>div>span::after {
content: ",";
display: inline-block;
padding-right: 0.3rem;
}
.globalclass>div:last-child>p::after, .globalclass>div:last-child>span::after {
content: ""; /* NOTE: If you want to end with a full stop change this to "." */
padding-right: 0;
}
- Inside this block, add a Paragraph block and change it’s html tag to span
- Click the dynamic content button and choose Repeater or Taxonomy Query respectively then select the field you want to display - for repeater fields this will be the field name, for taxonomy terms, this will usually be “name”
You should now see a comma separated list of terms. This can be useful for things like blog post categories/tags/terms, lists of authors or any other field with multiple values.
Notes:
- You may want to add a bottom margin to the
delimited-list
class depending on your usage - If you prefer, you can achieve the same end-result using relative styles instead of custom css
Hopefully this will save you some time in your projects.