Skip Navigation

[Resolved] Insert script into view

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 15 replies, has 3 voices.

Last updated by Beda 5 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#1190950

Hello Charles.

I apologise that it is one year since you have heard last from us.

There have been some misunderstandings initially, and a lot of priority on other aspects of Toolset Development, I am sure you noticed, that made it impossible for us addressing this problem properly.

I should have recognized a long time ago the difference between the working script and the not working script.

Adding a wrap value in the wpv-loop, enables you to use the item index later.
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-154381
>If you use the wrap or pad attributes, you can control the loop output with the [wpv-item] shortcode.
The thing is, this is not required, the Document is a bit misleading because you can use the [wpv-item] also without wrap/pad.
However what it wants to say is, that if you add wrap and pad, then wpv-item allows you to control the item in that new wrap loop.

Let's assume you target the first, the second, the split2 and the other items in a loop that has no wrap and pad and have 9 posts, all in one view.
Then you will receive all 9 posts styled by "other", unless the first, the second, and the one in the middle of all (floored split2) which is the 4th.
The others are using "other" index.
Example:

<wpv-loop>
         [wpv-item index=1] 
			Index 1
          [wpv-item index=2] 
			Index 2
          [wpv-item index=split2] 
			Index split2
          [wpv-item index=other]
          other
		</wpv-loop>

Result:

Index 1 Index 2 other Index split2 other other other other other

This is correct as the 1st, second, and 4th (floored split2 of all posts) are targeted, the ones that are not specifically targeted are using other.

NOTE:
If you accidentally cover the split2 result with a hardcoded index (so, in above example, accidentally we pass split2 index AND index=4), then index=4 wins over split2 and split2 won't be rendered anymore.

Let's switch to a wrapped (2) pad loop, still with 9 posts.
In this case, the loop begins again, every second post.
The item index values apply to each of these new loops.
So, the index=1 will address each first item in loops of 2 and index=2 every second post in those loopps. Index=3 does never apply because it never happens in this new loops.

Index split attributes are a little different, they have to target ALL posts, no matter the wrapping, but they will loose if the index already handles their position in the group.

In 9 posts, where the first, second and split2 is targeted and the loops are wrap 2 pad true, this means you will see the first, second of every wrap loop targeted.
Nothing else is output because there is no other left, and split2, which would fall on the 4th item (flooerd middle of all posts) is loosing against the defined index=1 or index=2 which already cover all possible spots in any loop.

In a loop of 9 wrapped by 2 the 4th item is the second item of the second group.
Hence you would have to not address the second items in a wrap 2 in order to target the split2. The split2 will then appear once - at the 4th position, second item of second group. All other second index items of the loops now would use "other", as not specified anymore with index=2.
In the case of 10 posts, where split2 is 5, the 5th item of the grand loop is the 1st item of the 3rd wrap loop.
That's targeted by index=1 already and hence, in this case you also do not see the split2.

That's why, bottom line, wrapping by 2 and adressing index 1 and 2, you never are able to see other kind of index items.

I hope I could exoplain this little complex espect well, please let me know.