Skip Navigation

[Resolved] Insert conditional HTML inside wpv-for-each

This support ticket is created 7 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
8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 8:00 – 14:00 - -
15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 15:00 – 17:00 - -

Supporter timezone: Asia/Jerusalem (GMT+02:00)

This topic contains 2 replies, has 2 voices.

Last updated by Binns 7 years, 11 months ago.

Assisted by: Itamar.

Author
Posts
#385937

Hi

I am using wordpress 4.3.3, View 2.0 and Types 2.01

I need to figure out a way of doing the following:

Loop through some images in a post
Before the last image is output include some other html

currently I have the following code inside a larger loop generating a post archive:

[wpv-for-each field="wpcf-gallery-image"]
    <div class="scroller_image_box">
        <img src="[types field="gallery-image" raw="true"][/types]" />
    </div><!-- scroller_image_box -->
[/wpv-for-each]

Is there any way that I can track the loop index and insert the other html when I get to the final image?

thanks
Paul

#386598

Itamar
Supporter

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+02:00)

Hello, Binns.

I'm sorry, but currently, there is no way to insert a condition in the [wpv-for-each field] shortcode.
Our documentation state this:
"Note: wpv-conditional shortcode won’t work inside a wpv-for-each shortcode"
https://toolset.com/documentation/views-shortcodes/#wpv-for-each

If you know in advance how many item you are going to have in this view, you can use the [wpv-item] with index=x attribute and add some HTML before the last item. Something like that:

<wpv-loop>
    [wpv-item index=1]
      <img src="[types field="gallery-image" raw="true"][/types]" />
    [wpv-item index=2]
      <img src="[types field="gallery-image" raw="true"][/types]" />
    [wpv-item index=3]
      <div>Some text here</div>
      <img src="[types field="gallery-image" raw="true"][/types]" />
 </wpv-loop>

If this is not the case and you can not anticipate how many items you will have then you can target the last element with CSS and insert some text before the last element.
Take a look at the following links that explain how to do it with CSS:
hidden link
hidden link

I've heard from our developers that there is a feature request to add an attribute index=last to [wpv-item] then everything would be easier for you.
Unfortunately, I can not say when this feature will be available.

Please let know if you need any more information regarding the issue that you bring here in this thread.

Thanks,
Itamar.

#391147

OK thanks for the info

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.