Skip Navigation

[Resolved] Echo index in repeting fields in WPV-FOR-EACH

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to display or show index for repeating field

Solution:
To display the repeating field index you need to add the custom shortcode to your current theme's functions.php file.

add_shortcode('show_index', 'func_show_index');
function incrementor() {
static $i = 1;
return $i ++;
}

You can find proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/echo-index-in-repeting-fields-in-wpv-for-each/#post-604274
Relevant Documentation:

This support ticket is created 6 years, 2 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by johanL-2 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#604087

I am trying to build a Bootstrap 3 Thumbnail silder/Carousel using repeting fields for the images.

<div class="carousel-inner">
                            <div class="active item" data-slide-number="0">
                                <img class="img-responsive" src="<em><u>hidden link</u></em>">
                            </div>
                            <div class="item" data-slide-number="1">
                              <img class="img-responsive" src="<em><u>hidden link</u></em>">
                            </div>
                            <div class="item" data-slide-number="2">
                                <img class="img-responsive" src="<em><u>hidden link</u></em>">
                            </div>

For full example see hidden link
I will use the [wpv-for-each field=""] to generate the class="item" but as you can see you need to set a number for each data-slide-number. Im thinking if using the index within the repeting field if possible.
[php]
[wpv-for-each field="wpcf-slider-images"]
<div class="item" data-slide-number="[index_of_repeating_field]">

<img src="[types field="slider-images" url="true"][/types]" class="img-responsive">
</div>
[/wpv-for-each]

</cod>

I have tried to do as described in:
https://toolset.com/forums/topic/echoing-index-in-wpv-for-each/
but I can not make it work. How should I do? to use the number of the index or can I do in another way?
BR
Johan

#604274

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - could you please try to use following shortcode:

Add following shortcode to your current theme's functions.php file:

add_shortcode('incrementor', 'incrementor');
function incrementor() {
static $i = 1;
return $i ++;
}

And try to use it as given underr:

[wpv-for-each field="wpcf-slider-images"]
<div class="item" data-slide-number="[incrementor]">
<img src="[types field="slider-images" url="true"][/types]" class="img-responsive">
</div>
[/wpv-for-each]

Do you see its working now?

#604884

Hi,
That work very good. I did create two incrementor one for the slider and one for the thumbnails.
Thanks a lot
/Johan

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