Add incremental counter in new_rs_slides_renderer_helper

faustogabiou's Avatar

faustogabiou

02 Oct, 2017 01:52 PM

Hello,

I created some custom variables using new_rs_slides_renderer_helper in a while loop. But as it uses a return, my incremental counter (++$counter) does not work. Is there a way to generate a counter for each gallery image?

  1. Support Staff 1 Posted by Dmitry Semenov on 02 Oct, 2017 04:59 PM

    Dmitry Semenov's Avatar

    Hello,

    You may use static variable to store index as well as current slider ID (which you can get via $options['id']), similar to how built-in WordPress [gallery] functionality works https://github.com/WordPress/WordPress/blob/master/wp-includes/medi...

    Also, if you're looking for a simple "1 of 10" indicator, you may implement it just via JS http://help.dimsemenov.com/kb/royalslider-javascript-api/creating-s...

  2. 2 Posted by faustogabiou on 02 Oct, 2017 08:35 PM

    faustogabiou's Avatar

    Hi Dmitry,

    Thanks for the lead! It's an ACF repeater field that I want to add the counter:

    function newrs_add_acf_variable($m, $data, $options) {
    $m->addHelper('gallery_content_description', function() use ($data) {
    $counter = 0;
    while ( have_rows('gallery_content') ) : the_row();
    return ++$counter . get_sub_field('gallery_content_description');
    endwhile;
    }
    add_filter('new_rs_slides_renderer_helper','newrs_add_acf_variable', 10, 4);

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac