that's my problem:

<?php
// start the loop
foreach($slider_posts as $post) : setup_postdata($post);
// get image
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'home-slide');
?>



<script type="text/javascript">
        $(function(){

            $.mbBgndGallery.buildGallery({
//              containment:"#wrapper",
                containment:"body",
                timer:5000,
                effTimer:5000,
                controls:"#controls",
                grayScale:false,
                autoStart:true,         



                images:[
                    "<?php echo $thumbnail[0]; ?> "





                ],


            });

                    });
    </script>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>

<?php } ?>

This code display just one slide image and not all slides images!

How Can I fix it?

link|improve this question
I don't think your script should be inside the foreach, but that the foreach should be inside the script. – Shane Feb 22 at 15:55
feedback

1 Answer

Try moving your foreach into the script tag, as such :

In the images parameter of your javascript :

 //[...]
 images:[
      <?php

      foreach( $slider_posts as $post )
      {

      $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'home-slide');

      echo '"' . $thumb[0] . '",'; //Assuming images are separated by a comma

      }          

      ?>
 ]

You may need to alter the example a bit to get it working properly.

Meta Example

 foreach( $slider_posts as $post )
 {
      $meta = get_post_meta( $post->ID, 'the-meta-field-name', true ); //replace true with false if you want an array of meta field results
 }
link|improve this answer
GREAT!!!!!!!!!!!!!!!!!!!!!!!!! is working!!! THANKS Shane! – user13401 Feb 22 at 17:12
No problem. Could you just accept the answer so the question can appear as resolved. – Shane Feb 22 at 17:46
just last question: To add post meta data from custom field fo each slide? – user13401 Feb 22 at 19:10
inside the foreach, use get_post_meta function. I'll add an example. Codex link : codex.wordpress.org/Function_Reference/get_post_meta – Shane Feb 22 at 19:16
sorry !thi code is correct to have a slideshow with text (with meta field)?? thanks! <?php foreach( $slider_posts as $post ) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'home-slide'); $meta = get_post_meta( $post->ID, 'the-meta-field-name', true ); echo '"' . $thumb[0] . '",' echo '"' . $meta[0] . '",'; //Assuming images are separated by a comma } ?> – user13401 Mar 7 at 17:46
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

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