How to use Loops to iterate over items

In version 2.8.0 of SNIP a long awaited feature came into the plugin. The feature is called “loop” and allows you to define a property to use a loop that it runs through. Here is how this works:

Why is looping needed?

Before we answer the questions how a loop works and how a loop can be set up I want to clarify why a feature like this is needed in SNIP.

We all strive to automate as much as possible. There are some Structured Data Snippets that could not be created with SNIP before version 2.8.0 because of some dynamic content produced by WordPress. Here is an example:

If you wanted to use the BreadCrumbList Schema you need to define a list of sites the current post is connected to. Let’s say you work with post categories a lot. A post maybe has a structure like this:

Home > Category 1 > Category 2 > Category 3 > The Post Title

Because the number of categories is different within every post it was not possible to create a BreadCrumbList Schema automatically. And of course it makes not much sense to create the Breadcrumbs manually in each post.

In version 2.8.0 and later it’s possible to choose a loop where a certain property runs through when it’s generated.

How to loop through a schema property

Because you work with categories you could choose that the property runs through all the ancestors. It then creates multiple itemListElements till the top-parent has been reached.

In the above example the loop would create three itemListElements: For Category1, Category2 and Category3.

Let’s take a look at the predefined breadcrumb example to see that in action:

The property list of a BreadcrumbList Schema. A loop has been chosen for a ListItem sub-property.