Hot answers tagged

14 votes

How can I create a visually weighted tag cloud?

Marion Newlevant had a clever, efficient idea in this Straight Up Craft Hangout if you don't mind having a slight lag (like a day) for your tag counts to be up to date. That idea: store the counts you ...
  • 3,986
13 votes

Removing whitespace from {{ tag.name }}

Craft has a filter for "Kebab Case", which I think is what you need. It strips out punctuation and replaces spaces with dashes. Useful if you need to format a field as a HTML attribute. {{ tag.name|...
  • 1,085
9 votes

Removing whitespace from {{ tag.name }}

I'm not sure if this feature is newer than this question but you can also say {{ tag.slug }} to get apples-and-carrots. All letters become lowercase as well so the result is more "scripting-friendly".
6 votes
Accepted

How can I group a list of tags into ranges of first letters (A–E, F–J, etc.)?

You can do this with the twigPCRE filter. Once you have your allTags, group them like this: {% set allTagsGrouped = allTags|group('name|first|upper|preg_replace("/[A-M]/", "A-M", 1)|preg_replace("/[N-...
6 votes
Accepted

How do I make the "%20" in URL's show as "-"

Edited I just learned this, but as of Craft 2.4, there's a kebab filter which you can use here. This would probably give you the effect you're after, where the string "two words" would become "two-...
6 votes

Get the Category name into the URL for an entry

A Categories field can be related to several categories. So you'll either need to limit your Category field to a single Category relationship or you'll need to make some assumption in how you build ...
  • 13.3k
6 votes

Deleting unused tags

There currently isn't any Tag management in Craft, but if you think there should be, consider voting for this feature request. In the meantime, there is a 3rd party plugin called Tag Manager that ...
  • 66.8k
6 votes
Accepted

How do I add a value to a tag field type using the entries service saveEntry method?

The Tags field classifiedTags needs an array of tag IDs, not slugs/titles. Also, if this is an existing entry and you want to retain tags already added to the field, you'll need to pull the existing ...
5 votes

Problem with accents in tags & URL

There is a general config setting for it: 'limitAutoSlugsToAscii' => true, Limits automatically-generated slugs to ASCII characters. When there is an obvious ASCII version of a character (e.g....
  • 3,734
5 votes

How can I make an oversized chalkboard organiser?

Definitely use a custom Element Type.
  • 13.3k
5 votes
Accepted

.relatedTo() not returning tags with spaces

In your working example, you’re mapping request.tags to the search param, but in the non-working example, you’re mapping it to the slug param. Those two params are handled in very different ways. ...
5 votes
Accepted

Query Entries by Tag

You'd need to get the tag model first. {% set tag = craft.tags.search('My Tag').first() %} {% if tag %} {% set entries = craft.entries.relatedTo(tag) %} {% endif %} Replace search with whatever ...
  • 36k
5 votes

How do I UNLOCK my account?

If you don’t have access to another admin account, you could unlock the account directly in the database. Change the lock value to 0 for the account in the craft_users table.
  • 36k
5 votes
Accepted

Confused about tags

You told Craft to look for tags/_tag And then you created templates/tags/_tags.html Note you have no s on the end in the route definition, but you do in the template name.
5 votes
Accepted

SEO titles/descriptions for tags and archive pages

The better approach in my opinion is to declare the variables in the corresponding templates rather than in the _layout template Layout.twig {% if seoTitle is not defined or seoTitle is empty %} ...
5 votes

Still not able to manage tags in Craft 3?

Short answer is "no, this still isn't possible". Longer answer is: The Tag Manager plugin from Craft 2 will not be ported. Pixel & Tonic have mentioned the possibility of rolling that ...
  • 23.7k
5 votes

How to delete tags in Craft CMS 3

Yes the same still applies. You can either delete it via DB directly in your {{%elements}} column or you can just run PHP Craft::$app->getElements()->deleteElementById(x) Twig {% do craft....
5 votes
Accepted

How to delete tags in Craft CMS 3

I do believe this plugin can help? https://github.com/ethercreative/tags
  • 1,032
4 votes

Search for related entries based on tags

Here's how you would exclude the current entry from showing within that output if so desired {% set entries = craft.entries({ relatedTo: tags, order: 'score', limit: 4, ...
  • 1,835
4 votes
Accepted

How do I display tags comma separated with "and" between the last two tags?

Bit of an old question, but here's a (subjectively) more elegant solution than the accepted answer using loop.revindex0: {% for tag in tags %} {{ tag.type }}{{ loop.revindex0 == 1 ? ' and' : loop....
  • 156
4 votes

How can I restrict tags that are able to be used?

That’s not possible, as tags are meant to be more of a “folksonomy” rather than a strict taxonomy. Sounds to me like categories would be a better fit for your needs. With those, the options are ...
4 votes
Accepted

Nested Matrix functionality for one block type using Tags

I just tried to replicate your setup (in simplified form), because I thought this is in fact an interesting and creative approach to do Matrix nesting that might come handy. Here's my code that works ...
  • 36k
4 votes
Accepted

How to populate a custom checkbox field with tag data dynamically?

I don't have enough reputation to post this as a comment, but this should help you pull the data on the front end with the LJ Dynamic Fields plugin. Install the LJ Dynamic Fields plugin. Create a '...
4 votes
Accepted

How can I use tag slugs in URLs?

The key to this is to use the |kebab filter and the relatedTo params. Listing: {% for tag in relatedTags %} <li><a href="/news/tags/{{ tag.title|kebab }}">{{ tag.title }}</a>&...
  • 3,225
4 votes

Listing All tags - and linking them to list of entries with that tag

You don't have a setting in Craft to make Tags have their own pages automatically. So what you have to do instead, is to set up a dynamic route in Settings → Routes. Create a new route which routes ...
  • 36k
4 votes

Plugin: Tags field for front-end Entry Form

While the full answer to this probably requires some planning, and a plugin that handles various aspects of the tag management, here are a few components to consider: You can submit tags from the ...
  • 13.3k
4 votes
Accepted

Show all tags related to a category?

You can use the relatedTo param on craft.tags like you can with any Element inside Craft. All Elements inside Craft can be related to one another. There is a .relatedTo parameter available on all of ...
  • 3,843
4 votes

List entries for a single tag from blog section

You were very close! You are looping through craft.entries.section('blog') which doesn't use your tag query. You simply need to loop through the results of your query which you've set in the entries ...
  • 3,843
4 votes
Accepted

How to display number of entries for a tag and not display if no entries?

Something like this should work: {% set tags = craft.tags.limit(null).relatedTo(craft.entries.limit(null)).order('title') %} {% for tag in tags %} <a href="/tags/{{ tag.slug }}">{{ tag....
4 votes
Accepted

Where are tags stored in the database?

Tags are Elements and are stored in multiple places in the database, so editing the db directly may not be as easy as just finding the Tags you want and deleting them. The tag itself is stored in ...
  • 13.3k

Only top scored, non community-wiki answers of a minimum length are eligible