Post tags

Post item represent posts written in Publii:

  • {{id}} - post ID
  • {{title}} - post title
  • {{featuredImage}} - featured image item
  • {{tags}} - array of tag items
  • {{hiddenTags}} - array of tag items which are marked as hidden
  • {{author}} - post author item
  • {{slug}} - post slug used in URL
  • {{url}} - post page URL
  • {{text}} - post full text
  • {{excerpt}} - post excerpt text
  • {{createdAt}} - post creation date
  • {{modifiedAt}} - post modification date
  • {{status}} - post status (hidden, draft, featured)
  • {{template}} - template name used in the post
  • {{isFeatured}} - true if post is featured
  • {{isHidden}} - true if post is hidden
  • {{hasGallery}} - true if post contains a gallery
  • {{hasCustomExcerpt}} - true if post contains a custom excerpt content
  • {{mainTag}} - tag item representing the post's main tag, selected manually or automatically. Returns false if the post has no visible tags. See how the main tag is selected.
  • {{postViewConfig}} - object with additional post view-related configuration (if available in the theme

How the main tag is selected

Each post can have one main tag. Publii determines the value of {{mainTag}} using these rules:

  • If a main tag is selected manually, Publii uses that tag, provided it still exists and is not hidden.
  • If no main tag is selected, or the selected tag is unavailable or hidden, Publii uses the first visible tag in alphabetical order by name.
  • If the post has only one visible tag, that tag becomes its main tag automatically.
  • If the post has no visible tags, including when all its tags are hidden, {{mainTag}} returns false.

The automatic selection is calculated when Publii generates the site. It does not save a manual selection in the post editor. Leaving the Main tag field unset therefore still allows the theme to use an automatically selected main tag.

For example, a post tagged Editorial and Field notes, with no manually selected main tag, uses Editorial. Selecting Field notes manually overrides this automatic choice.

Main tag lists and filters

From Publii 0.48.4, the mainTags array includes both manually and automatically selected main tags from published, non-hidden posts. Drafts, trashed posts, hidden posts and pages do not contribute to this list.

On the homepage, posts marked Excluded from homepage do not contribute either. Their main tag can still appear if another eligible post uses it as its main tag. This homepage restriction does not apply to main tag lists in other contexts.

Each post contributes at most one main tag. Additional tags assigned to that post do not become main tag filter options unless another eligible post uses them as its main tag. The list contains each tag once, in alphabetical order, and respects the site's empty-tag display setting.

The homepage list covers eligible posts across all pagination pages. Themes that build filters from mainTags use this list.

Create your first website with Publii

Join thousands of creators who chose independence. Create content locally and publish lightning-fast, secure websites on your own terms.

Download Publii

Free and open source. Windows, macOS and Linux.

Read the getting started guide