Is there a way to make a calculation in "Looper Provider" -> "Count"?

Hello, I want to display a list with the post tiles of a particular custom post type in two columns. I want the items to be ordered alphabetically, going in ascending order through the first column, and then continuing in the second one, something like this:
•1 •7
•2 •8
•3 •9
•4 •10
•5 •11
•6

If I use a single row with two columns the items populate the rows first, and then overflow to the next column, looking like this:
•1 •2
•3 •4
•5 •6
•7 •8
•9 •10
•11

I thought I’d populate two separate columns, the first with the first half of the posts within the custom post type, and the second with the other half of the posts.

For this I thought I could do a calculation in the “count” field using {{dc:looper:count}} for the first column, something like
={{dc:looper:count}}/2

And then do the same for the second column, including an offset of half the count.

But so far I have not found a way to solve this.

Looper

Is there a way to solve this?

Thanks in advance

Hello Oriol,

Thanks for writing in!

You can achieve what you have in mind by having a Looper Provider and two Looper Consumer. Please take a look at my example layout structure:

Screen Shot 2021-09-27 at 10.19.30 AM

In your Looper Consumer 1, you can add the condition “Index is Even”.
In your Looper Consumer 2, you can add the condition “Index is Odd”.

You can download this sample block template file and insert it to your custom layout:

Hope this helps.

Thanks, I think this helps with spacing, with the single row, two-column layout I was getting weird spacing because of the difference in height (some lines wrapping):

However, using odd/even gives the same result regarding alphabetically sorting the results:

Hello Oriol,

Sorry for the confusion. Now, I get the correct order for the display. You can still have the same layout as I have pointed out in my previous response. You need to remove the conditions. And then in each of your Looper Consumer, set it to “Many”.

Screen Shot 2021-09-27 at 12.43.56 PM

I used 6 on my test template so that 6 items will be displayed on the left and the remaining post items will be on the right.

Download this sample block template here:

Hope this finally works out for you.

Thank you very much @ruenel, however, the problem is that my client will be adding more posts of this type, thus, it won’t be a static number. That’s why I thought about doing a calculation with {{dc:looper:count}}.

Hello @Oriol,

Please be advised that the Looper Provider item count ({{dc:looper:count}}) will only display the total number of post items set in Settings > Reading > Blog pages show at most. By WordPress default, it is 10 items only. You may need to use a fix valued if you want to display more than what is set in the settings.

Hope this makes sense.

I was planning on increasing the pages shown to 999 (more than the items that would be created). Is there a way to do a calculation within the “count” or “items” fields?

Hi @Oriol,

Regretfully, there is no option to do any calculation with the Count or Items field.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.