Cheat Sheet: craft.entries

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

{% set entries = craft.entries({
  id:             id OR 'not id' OR '1,2,3' OR [1,2,3],
  fixedOrder:     true OR false,

  slug:           'slug', 
  uri:            'uri', 
  sectionId:      id,
  section:        'sectionHandle', ['handle','handle'], 
                  SectionModel, [SectionModel,SectionModel],
  locale:         'en_us',
  localEnabled:   true OR false,
  authorId:       id,
  authorGroupId:  id,
  authorGroup:    id,
  after:          'YYYY,YYYY-MM,YYYY-MM-DD,YYYY-MM-DD HH:MM,YYYY-MM-DD HH:MM:SS',
  before:         'Unix timestamp,DateTime variable',
  status:         'live,pending,expired,disabled,null',
  archived:       true OR false,
  offset:         number,

  ancestorOf:     EntryModel OR id,
  ancestorDist:   level, {# number of levels above ancestorOf #}
  descendantOf:   EntryModel OR id,
  descendantDist: level, {# number of levels below descendantOf #}
  nextSiblingOf:  EntryModel OR id,
  prevSiblingOf:  EntryModel OR id,
  level:          level, {# for Structure entries #}

  order:          'title,id,authorId,sectionId,slug,uri,postDate,expiryDate desc',
  limit:          number,
  indexBy:        'id,title',

  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 entry in entries %}
  
  {# EntryModel #}

  {# Properties #}
  {{ entry.ancestors }}
  {{ entry.author }}
  {{ entry.authorId }}
  {{ entry.children }}
  {{ entry.cpEditUrl }}
  {{ entry.dateCreated }}
  {{ entry.dateUpdated }}

  {{ entry.descendants }}
  {{ entry.enabled }}
  {{ entry.expiryDate }}
  {{ entry.id }}
  {{ entry.level }}
  {{ entry.link }}
  {{ entry.locale }}

  {{ entry.next }}
  {{ entry.nextSibling }}
  {{ entry.parent }}
  {{ entry.postDate }}
  {{ entry.prev }}
  {{ entry.prevSibling }}
  {{ entry.section }}
  {{ entry.sectionId }}

  {{ entry.siblings }}
  {{ entry.slug }}
  {{ entry.status }}
  {{ entry.title }}
  {{ entry.type }}
  {{ entry.uri }}
  {{ entry.url }}

  {# Methods #}
  {{ entry.getAncestors( distance ) }}
  {{ entry.getAuthor() }}
  {{ entry.getChildren() }}
  {{ entry.getCpEditUrl() }}
  {{ entry.getDescendants( distance ) }}
  {{ entry.getLink() }}

  {{ entry.getNextSibling() }}
  {{ entry.getParent() }}
  {{ entry.getPrevSibling() }}
  {{ entry.getSection() }}
  {{ entry.getSiblings() }}
  {{ entry.getUrl() }}
  {{ entry.isAncestorOf( entry ) }}

  {{ entry.isChildOf( entry ) }}
  {{ entry.isDescendantOf( entry ) }}
  {{ entry.isNextSiblingOf( entry ) }}
  {{ entry.isParentOf( entry ) }}
  {{ entry.isPrevSiblingOf( entry ) }}
  {{ entry.isSiblingOf( entry ) }}

  {% set prev = entry.getPrev( params ) %}
  {% set next = entry.getNext( params ) %}
  {% if prev %} <a href="{{ prev.url }}">{{ prev.title }}</a> {% endif %}
  {% if next %} <a href="{{ next.url }}">{{ next.title }}</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.