mercredi 28 janvier 2015

Trying to uswp_localize_script with Advance Custom Fields Repeater


I have an external javascript file that I am trying to change dynamically:


Here is the Javascript that I want to be dynamic



{image : 'http://ift.tt/16ai81w', title : 'Chakra'}
{image : 'http://ift.tt/1yDmvsC', title : 'Responsive Design'},
{image : 'http://ift.tt/16ai81A', title : 'FullScreen Gallery'},
{image : 'http://ift.tt/1yDmu88', title : 'Showcase Your Work'}


Here is the current way I am coding my PHP



$slider1 = get_field('slider_image_1','option');
$slider2 = get_field('slider_image_2','option');
$slider3 = get_field('slider_image_3','option');
$slider4 = get_field('slider_image_4','option');
$caption1 = get_field('slider_caption_1','option');
$caption2 = get_field('slider_caption_2','option');
$caption3 = get_field('slider_caption_3','option');
$caption4 = get_field('slider_caption_4','option');

$images = array(
array("image" => $slider1, "title" => $caption1),
array("image" => $slider2, "title" => $caption2),
array("image" => $slider3, "title" => $caption3),
array("image" => $slider4, "title" => $caption4),
);

wp_register_script( 'main', trailingslashit( THEME_URI ) .'_include/js/main.js', false, '1.0', true );
wp_localize_script( 'main', 'My_Slide_Images', $images );
wp_enqueue_script( 'main' );


Here is what I want to attempt to do with my PHP:



if (have_rows('add_a_slide','option')) {
$images = array();

foreach (get_field('add_a_slide','option') as $slide) {
$images[] = array(
"image" => $slide[get_sub_field('slide_image','option')], "title" => $slide[get_sub_field('slide_caption','option')],
);
}
}

wp_register_script( 'main', trailingslashit( THEME_URI ) .'_include/js/main.js', false, '1.0', true );
wp_localize_script( 'main', 'My_Slide_Images', $images );
wp_enqueue_script( 'main' );


What do I need to change in order to make the repeater work?





Aucun commentaire:

Enregistrer un commentaire