Overview

Loops & Logic is a template system for WordPress.

It brings together three concepts:

  • Content loops
  • Conditional logic
  • A template language

Loop

A loop can be created from any content type on a WordPress site.

It's a standard interface to query for items of any type, and loop through each one to get or display its fields.

The goal is to have comprehensive coverage of all content in the database. Supported content types include posts, pages, custom post types, attachments, taxonomies, users.

An example use case: a loop of three most recent posts, to create a list with each title linked to a post.

For details, see the Loop and Field tags.

Logic

Logic is used to display something based on certain conditions.

An example: creating a menu, with some links only for logged-in users, or by user role.

There is a library of defined logic rules, to cover common use cases.

Each rule is made of three parts.

  • Field - Subject of the condition, like user or user_role
  • Comparison - exists, includes
  • Value - administrator

For details, see the If tag.

Template

A template is written in HTML, extended with dynamic tags.

Here's an example.

<ul>
  <Loop type=post count=3 orderby=date order=desc>
    <li>
      <a href="{Field url}"><Field title /></a>
    </li>
  </Loop>
</ul>

The above template will create a list of links to the three most recent posts.

This is similar to shortcodes, which are replaced by dynamic content.

The template system in Loops & Logic is an evolution of shortcodes, to provide a flexible and extensible language.


Next: Templates