Cheat Sheet: craft.tags

{# craft.tags tag #}
{% set tags = craft.tags.first() %}
{% set tags = craft.tags.last() %}
{% set tags = craft.tags.find() %}
{% set tags = craft.tags.ids() %}
{% set tags = craft.tags.total() %}

{% set tags = craft.tags({
  id:             id OR 'not id' OR '1,2,3' OR [1,2,3],
  fixedOrder:     true OR false,
  name:           'name', 
  group:          'handle',
  groupId:        id,

  order:          'id,setId,name asc',
  limit:          number,
  indexBy:        'id,name',

  locale:         'en_us',
  offset:         number,

  relatedTo:      AssetFileModel, EntryModel, UserModel, 
                  CategoryModel, TagModel,
                  elementId,
                  [ arrayOfModels, arrayOfModels, arrayOfModels ],
                  [ 1, 2, 3 ],
                  craft.assets, craft.categories, craft.entries,
                  craft.tags, craft.users    

  search:         'salty dog'           containing both "salty" and "dog"
                  '"salty dog"'         containing the exact phrase "salty dog"
                  'salty OR dog'        containing either "salty" or "dog" (or both)
                  'salty -dog'          containing "salty" but not "dog"
                  'body:salty'          containing "salty" in the "body" field
                  'body:salty'          body:dog containing both "salty" and "dog" 
                                        in the "body" field
                  'body:*'              containing anything within the "body" field
                  'salty locale:en_us'  containing "salty" in the locale "en_us"
                  'salt*'               containing a word that begins with "salt"
                  '*ty'                 containing a word that ends with "ty"
                  '*alt*'               containing a word that contains "alt"

}) %}

{% for tag in tags %}
  
  {# TagModel #}

  {# Properties #}
  {{ tag.id }}
  {{ tag.name }}
  {{ tag.locale }}
  {{ tag.next }}
  {{ tag.prev }}
  {{ tag.groupId }}

  {# Methods #}
  {% set prev = tag.getPrev( params ) %}
  {% set next = tag.getNext( params ) %}
  {% if prev %} <a href="/link-to-prev-tag">{{ prev.name }}</a> {% endif %}
  {% if next %} <a href="/link-to-next-tag">{{ next.name }}</a> {% endif %}

{% endfor %}

Level up in Craft CMS with practical examples, snippets, and patterns.
Craft The Planet emails are sent out several times a week.