Post Template Reference

Post templates are a powerful and flexible feature that allow you to customize how posts appear in your blog. Post templates allow you to randomize the format to give your blog a fresh and natural-looking appearance. You can use post templates to display images, video, flash, audio, custom HTML, or even client-side scripts.

All feeds in AutoBlogged have a default template that will modify the feed and add uniqueness to each post. You can set templates for any feed by editing the details of that feed. The feed syntax described below also works when defining custom fields.

Note that post templates consist of HTML markup so carriage returns and other whitespace is ignored.

Note that the template processing engine does minimal syntax checking so enter your templates carefully and double-check them when you get unexpected results.

Variables

Inserting Variables

With post templates you can refer to any item in the feed or any information extracted by visiting the original URL.

You can insert variables into your post template by surrounding them with percent signs (%). For example, to insert the current title, use %title% in your template.

Built-In Variables

By default, most feed items will set the following variables that you can insert into your templates:

  • %title% – The title of the feed item
  • %link% – The unique URL for the original article, often referred to as the permalink or guid.
  • %content% – The body of the feed content, which may contain HTML or other markup.
  • %excerpt% – A text-only excerpt of the body content.
  • %date% - The date the item was published or, if not available, the current date.

Furthermore, many feeds will also provide the following:

  • %source% – The source of the feed, such as the web site or blog name.
  • %source_url% – The main URL of the feed source.
  • %source_description% – Short description of the source web site.
  • %author% - The author of the post, if available.
  • %copyright% – Any copyright notice included with the feed.
  • %copyright_url% – A URL for more copyright information.
  • %icon% – The favicon for the source web site.
  • %logo_url% - The logo for the source web site.
  • %logo_link% – The link to use when making the logo into a hyperlink.
  • %logo_title% - The title to use with a logo hyperlink.
  • %tags% – All tags assigned to the post.
  • %image% – The first image attachment found in feed item returned as a formatted image tag.
  • %images% – All image attachments, returned as as a formatted image tag.
  • %video% – The first video found in the feed item returned as an embedded flash or video object.
  • %videos% – All video attachments, returned as an embedded flash or video object.

If when adding a post the name of the author already exists in your blog, you can also refer the the following variables:

  • %author_id% - The WordPress author ID.
  • %author_display_name% – The WordPress display name for the author.
  • %author_email% – The author’s e-mail address.
  • %author_url% – The author’s URL.

You may also use any of the following special variables:

  • %original_page% – The full content of the page located by following %link%. Note that this is the raw, unformatted contents of the entire original page and normally will not be useful for using within a template.
  • Any other custom field you have set.

Advanced Features

Random Select Lists

You can have the post template randomly select one of a list of items to give your blog a more natural appearance. To do this, use percent signs (%) and brackets ([]) on the outside and pipes (|) between each item.

Syntax:

[value1|value2|value…]

Example:

[Read more|See original|Continue here]

This will randomly return either Read more, See original, or Continue here.

First Available Lists

Because there are so many feed types and namespace extensions in use, and it is not uncommon to see feeds that do not follow standards, it is possible to work through a list of items until you find one that is not empty.

You can specify a first available list by using percent signs (%) and braces ({}) on the outside and pipes (|) between each item.

Syntax:

{variable1|variable2|variable…}

Example:

{%source%|%author%|%title%}

This will check the value of the %source% variable. If empty, it will use check the %author% variable and if still empty will use the %title% variable. If all variables are empty the list will return nothing.

Note that in order to provide a default value, set the last item as static text as follows:

{%source%|%author%|%title%|Source Unknown}

Note that although you can use variables in First Available lists, you cannot embed nested lists within a list. The same is true for Random Select lists.

Conditional Select Blocks

Conditional select blocks are simple if-then constructs that simply show the enclosed content if the variable is set in the feed. If the variable is not set, AutoBlogged skips the entire block. This is useful to display images or video only if those items exist.

Conditional select blocks contain a tag at the beginning and end of the block, with the conditional content in between.

Syntax:

%if:variable%
content
%endif:variable%

Example:

%if:image%
Photo: %image%
%endif:image%

The block of code Photo: %image% will only appear if the feed item contains an image.

Loop Blocks

Some item variables may contain more than one value, so all variables that are plural will return a comma-separated list of values. If you wish to customize the display of each value, you can do that with loop blocks.

A loop block will repeat the enclosed content for each value in the variable. When enclosed in a loop block, the plural form of the variable will only return the current item in the loop.

Syntax:

%foreach:variable%
content
%endfor:variable%

Example:

%foreach:images%
Photos:<br><%images%>
%endfor:images%

This template will repeat the content Photos:<br><%images%> for each image in the feed item. Note that if there are no images in the feed item the content will not be displayed, having the same affect as using a conditional select block. The default variables that might contain multiple values are %categories%, %tags%, %images%, and %videos%.

Regular Expression Function

The regular expression function is the most powerful post template feature that AutoBlogged offers. With the regular expression function you can extract content using the power of regular expressions.

Syntax:
%regex(“%variable%”, “pattern”, “element”, “delimeter”)%

Example:

%regex("%page_content%", "\b([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\b", "0", ", ")%

This example will return a comma-separated list of all domain names on the original page. Note that the %page_content% variable is only populated if you have AutoBlogged configured to visit the source URL to extract additional tags.

%regex("%excerpts%", "\b([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\b", "0")%

This example will extract the first domain name mentioned in the excerpt.

%regex("%link%", "\b([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\b", "1")%

This example will return the domain name from the original link without the TLD. For example, if the link is http://example.com, the pattern will return example.

Parameters:

%variable% – This is any simple post template variable, such as %title% or %page_content%. Note that you cannot use complex functions here such as random select lists, first available lists, or Loop blocks. If you wish to use these, you must first use them in a custom field and then use that custom field in your regular expression function.

pattern - This is the regular expression pattern. Due to the formatting of the post templates, use \x25 for the percent sign (%) and \x22 for a quotation mark (“).

element - This allows you to return a submatch from your regular expression. The default value of 0 returns the whole match, 1 returns the first submatch, etc.

delimeter - If there are multiple matches, they will all be returned separated by this delimeter. If this option is ommitted, only the first match will be returned.

Multiple Templates

AutoBlogged allows you to make a list of templates to randomly choose from when adding a post. Place the string <!– template –> between each template as a separator

Example Post Template

Below is a full example of a post template that utilizes many of the elements described on this page:

<p>%excerpt%</p>

[Read more here|Read the original here|
Read more from the original source|
Continued here|Read more|More here]:
<a href="%link%" title="%title%">%title%</a>

<!--template-->

<p>[This is from|Here's %category%-related post from|From]
<a href="%sourceurl%" title="%title%">%source%</a>:</p>

<blockquote>
%excerpt%
</blockquote>

[Read more|More|Continue here]:
<a href="%sourceurl%" title="%category%: %title%">%title%</a>

<!--template-->

Here's [an interesting|a good|a new] [post|article] from %source%:

%excerpt%

[Continue|More] here: <a href="%link%" title="%title%">%title%</a>

Recent Tweets

    No public Twitter messages.


Delicious Save this on Delicious


@AutoBlogged
Find us on Google+