Skip to main content
All CollectionsDynamic ShortcodesFeatures
How to Loop Posts with Dynamic Shortcodes
How to Loop Posts with Dynamic Shortcodes
Updated over a week ago

With the Loop Dynamic Shortcode you can comfortably loop over posts by setting the current post at each iteration. Freeing you from the need to reference the post ID when displaying its data.

If you want to loop over something other than WordPress posts use the for instead.

Syntax

{loop:array-of-post-id-here template @ sep=','}

  • array-of-post-ids An array of post IDs to loop over. These IDs can be provided by another Dynamic Shortcode like query, or directly specified using {array} with explicit IDs that represent valid posts within your WordPress database.

  • template The template to be printed at each iteration. This can be a complex template or a single Dynamic Shortcode.

Keyargs

  • separator (alias sep): Defines a string to separate each iteration's output. The default is an empty string, but you can specify separators like commas, spaces, or HTML tags to suit your layout needs.

Examples

Display a list of links to posts.

<ul>
{loop:
{query:posts}
[<li><a href="{post:permalink}">{post:title}</a></li>]}
</ul>

This example demonstrates how to use the Loop Dynamic Shortcode to fetch and display post titles from a generic query, with a separator between each title. This method is particularly useful when you want to display a list of titles in a single line or within a specific formatting context.

{loop: 
{query:posts}
[{post:title}]
@sep=', '
}
Did this answer your question?