Get the free theme
View Categories

Using Tokens in Blog Posts

2 min read

The Loupely Canvas blog fills your post markup with values using tokens. You write the markup for a post once, drop in a token wherever a value should go, and the theme swaps in the real value when the page renders. This article covers every token and where each one works.

How tokens work

A token is a word in braces, like {title} or {content}. You put it in your Post card or Single post markup on the Blog templates screen (Appearance, Loupely Canvas), and the theme replaces it with that post’s value. Everything around the token is your raw HTML, left untouched. Each value is escaped on its own as it goes in, so the dynamic part is filled safely and nothing else is styled or added for you.

Per post tokens

These work in the Post card box, repeated for each post in a list, and in the Single post box, for one full post:

  • {title} the post title.
  • {permalink} the post’s URL, for your own links to it.
  • {date} the published date.
  • {author} the author’s name.
  • {content} the full post body. Use it in the Single post box.
  • {excerpt} the short excerpt. Use it in the Post card box.
  • {thumbnail} the featured image as a ready image tag.
  • {thumbnail_url} just the featured image URL, for a CSS background.
  • {categories} and {tags} the post’s categories and tags, as linked lists.
  • {author_avatar} the author’s photo as a ready image tag.
  • {author_bio} the author’s bio from their profile.
  • {author_url} the author’s website link from their profile.
  • {comment_count} the number of comments on the post.
  • {comments_link} the URL to the post’s comments.
  • {post_class} the post’s own WordPress classes, for a wrapper, so you can style a card by category, tag, or sticky state.

{post_class} goes in a class attribute on your outer element, where it adds classes like the category and tag slugs and a sticky marker:

<article class="post-card {post_class}"> ... </article>

Archive header tokens

In the Archive header box, which prints above category, tag, date, author, and search lists:

  • {archive_title} the title of the current archive, such as a category name or the search query.
  • {archive_description} the archive’s description, where one is set.
  • {search_form} a ready search box. It also works in the 404 box.

The 404 box tokens

In the 404 box:

  • {home_url} your homepage address, for a link back home.
  • {search_form} a ready search box, so a wrong URL can lead somewhere useful.

A worked example

A Single post template using a handful of tokens:

<article class="coffee {post_class}">
  {thumbnail}
  <h1>{title}</h1>
  <p class="origin">{date} by {author}</p>
  <!-- tasting notes live in the post body -->
  <div class="body">{content}</div>
  <p class="meta">{categories} {tags}</p>
  <p class="talk"><a href="{comments_link}">Comments ({comment_count})</a></p>
</article>

Style the classes, coffee, origin, body, meta, and talk, however you like in your Head code box. The tokens are the only part the theme fills; the rest is yours. Writing the comment link as Comments ({comment_count}) reads correctly at any count, where a bare {comment_count} comments would misfire at 1.

What is and is not a token

The comment thread and the previous and next post links are not tokens. On a single post, the theme adds them below your Single post markup on its own, using standard WordPress markup you style yourself, so there is nothing to place for them. The comment count and the comments link, on the other hand, are tokens, so you can show a count and link to the thread from a card or a single post. For turning comments on and styling the thread, see comments on your blog. For the tokens that work in the site header and footer, which are a different set, see using tokens in the header and footer. For the full blog setup, see how to set up a blog in Loupely Canvas.