There are a few new fun features being sent your way with version 2.4.4 of Loops & Logic. Here’s the inside scoop about what’s changed and how you can put it to use.

Create variables from the Math tag faster using the new math variable

A new math variable is now available that combines the powers of the Set tag with the Math tag. Saving the output of a mathematical equation used to require placing a Math tag as the inner contents of a Set tag. Now, you can do that with just a single tag. For example, the markup below creates a variable called my_total and sets it based on the math between the opening and closing tags.

  <Set math=my_total>10+7</Set>

In this example, you could then use <Get math=my_total /> to display the saved mathematical output, which in this case would be 17.

Set up conditional logic if a query exists using the new query condition

The query variable type is one of the most useful tools for building fast, efficient L&L templates. It allows you to save an entire query (i.e. a loop) and reference it throughout a template without needing to perform the same query again and again. With the latest update, L&L’s If tag now accepts a query condition, allowing your markup to conditionally run certain L&L code depending on whether a specific query variable exists.

  <Set query=my_saved_query type=post count=3 />
  
  <If query="my_saved_query" exists>
    <Loop query=my_saved_query>
      <Field title />
    </Loop>
    <Else />
    The saved query does not exist.
  </If>

Loop through lists without needing to use the List tag

Version 2.4.4 includes now allows you to loop through multiple items in a comma-separated list without the need to create the list in the first place using the List tag. The standard way of creating a list loop would be to first build all the items in a list and then loop through that list, as shown below:

  <List name=oz>
    <Item>lions</Item>
    <Item>tigers</Item>
    <Item>bears</Item>
  </List>

  <Loop list=oz>
    Item number <Get loop=count /> in this list is: <Field /><br />
  </Loop>

The latest version of Loops and Logic allows the comma-separated list to be declared directly inside the Loop tag using the items parameter. This can be helpful if you already have a comma-separated list saved as a variable (in which case you could create a loop with <Loop items="{Get my_list_variable}">) or in instances where it’s faster to simply create a short list instead of building the list using List and Item tags, as shown below.

  <Loop items=lions,tigers,bears>
    Item number <Get loop=count /> in this list is: <Field /><br />
  </Loop>

New scroll-to-top option and more for loop pagination

L&L’s loop pagination offers a convenient way to split up your loops using AJAX pagination. Following some user requests, the scroll_top=true attribute on the PaginateButtons tag in version 2.4.4 now adds the ability to make the browser scroll to the top of the page when the user navigates to a new page. This can be helpful if your loop is displaying more content than can fit on the user’s screen. By default, the scrolling motion to the top of the loop is animated with a smooth scrolling effect. To change this animation, you can either use the scroll_animate=false attribute to make the browser immediately jump to the top of the loop or you can use the same attribute to animate duration in milliseconds (default is 300). In practice, a paginated loop that quickly scrolls to the top of the loop when changing pages would have markup that looks like this:

  <Loop type=post paged=10>
    <Field title /> <br />
  </Loop>
  <PaginateButtons scroll_top=true scroll_animate=150 />

The latest update also allows L&L’s loop pagination feature to support ACF relationship fields as well as supporting randomized ordering using the orderby=random attribute.

Is that all?

Nope. This update also includes the following fixes and features:

  • Improved compatibility with Elementor version 3.0 by using register_controls() instead of deprecated _register_controls()
  • The template editor now correctly saves updates to the template category. This fixes an issue where browsers autocomplete changes checkbox values
  • The template variable type now passes attributes from the Get tag as local variables to the template on which a template tag is placed.

Leave a Reply

Your email address will not be published.