0

I feel like I’m so close, but just need someone to help assist me with getting this working. I’m using a repeater field with Advanced Custom Fields and am using the echo shortcode, but only need part of it to repeat in the loop.

See my code below:

<?php
// check if the repeater field has rows of data
if( have_rows('homepage_slider') ):
// loop through the rows of data

// display a sub field value
echo do_shortcode('
[ux_slider timer="4500" arrows="true" bullets="true" auto_slide="true" nav_color="light"]

' . while ( have_rows('homepage_slider') ) : the_row(); . '

[ux_banner bg=" ' . get_sub_field('slider_image') . ' " height="600px" text_color="light" text_align="center" text_pos="center" text_width="70%" parallax_text="0" parallax="3" effect="sparkle"]

<h1>' .  get_sub_field('slider_slide_title') . '</h1>
<h4 class="thin-font">' . get_sub_field('slider_sub_title') . '</h4>
[/ux_banner]

' . endwhile; . '

[/ux_slider]');

else :
// no rows found
endif;
?>

Seems to be the placement of the “while” and “endwhile”, but the ux_banner is the only shortcode I want to repeat. How do I use "while" and "end while" inside of the echo do_shortcode? Let me know if you have any thoughts/ideas, thanks so much for the help.

1 Answer 1

0

You need to generate the shortcode within the loop, and then execute it afterwards:

if ( have_rows( 'homepage_slider' ) ) {
    $shortcode = '[ux_slider timer="4500" arrows="true" bullets="true" auto_slide="true" nav_color="light"]';

    while ( have_rows('homepage_slider') ) {
        the_row();

        $shortcode .=
'[ux_banner bg=" ' . get_sub_field( 'slider_image' ) . ' " height="600px" text_color="light" text_align="center" text_pos="center" text_width="70%" parallax_text="0" parallax="3" effect="sparkle"]
    <h1>' .  get_sub_field( 'slider_slide_title' ) . '</h1>
    <h4 class="thin-font">' . get_sub_field( 'slider_sub_title' ) . '</h4>
[/ux_banner]';

    }

    $shortcode .= '[/ux_slider]';

    echo do_shortcode( $shortcode );
}
1
  • Worked perfectly! That's exactly what I was looking for! Thank you Sooooo much!
    – Jason
    May 14, 2015 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.