I am creating a slider, and I need to pull out specific values from an array to add them to the slider.
From what I understand, the best way to do this is a foreach loop. I found a function to spit out the images as an array, but I can’t figure out how to pull out the specific values.
I’ve started with $image_array = spit_it_image_array();
The markup for the slider would look like:
<div id="post-default-slider" class="royalSlider rsDefault">
<div class="aSlide">
<img src="from-the-array.com/img1.jpg">
<p> maybe the caption goes here </p>
</div>
<div class="aSlide">
<img src="from-the-array.com/img2.jpg">
<p> maybe the caption goes here </p>
</div>
<div class="aSlide">
<img src="from-the-array.com/img3.jpg">
<p> maybe the caption goes here </p>
</div>
</div>
An example of an array for an image looks like:
array(6) { [0]=> object(stdClass)#2538 (14) { ["ID"]=> string(3) "320" ["post_id"]=> string(3) "372" ["date_gmt"]=> string(19) "2021-04-26 13:49:29" ["user_id"]=> string(1) "1" ["other_id"]=> string(1) "0" ["title"]=> string(0) "" ["caption"]=> string(0) "" ["file"]=> string(28) "/2021/04/restaurants19-2.jpg" ["mime_type"]=> string(10) "image/jpeg" ["menu_order"]=> string(1) "0" ["featured"]=> string(1) "1" ["is_approved"]=> string(1) "1" ["metadata"]=> string(2371) "a:5:{s:5:"width";i:580;s:6:"height";i:386;s:4:"file";s:27:"2021/04/restaurants19-2.jpg";s:5:"sizes";a:14:{s:9:"thumbnail";a:4:{s:4:"file";s:27:"restaurants19-2-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:27:"restaurants19-2-300x200.jpg";s:5:"width";i:300;s:6:"height";i:200;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_218x150";a:4:{s:4:"file";s:27:"restaurants19-2-218x150.jpg";s:5:"width";i:218;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_324x400";a:4:{s:4:"file";s:27:"restaurants19-2-324x386.jpg";s:5:"width";i:324;s:6:"height";i:386;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_485x360";a:4:{s:4:"file";s:27:"restaurants19-2-485x360.jpg";s:5:"width";i:485;s:6:"height";i:360;s:9:"mime-type";s:10:"image/jpeg";}s:8:"td_80x60";a:4:{s:4:"file";s:25:"restaurants19-2-80x60.jpg";s:5:"width";i:80;s:6:"height";i:60;s:9:"mime-type";s:10:"image/jpeg";}s:9:"td_100x70";a:4:{s:4:"file";s:26:"restaurants19-2-100x70.jpg";s:5:"width";i:100;s:6:"height";i:70;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_265x198";a:4:{s:4:"file";s:27:"restaurants19-2-265x198.jpg";s:5:"width";i:265;s:6:"height";i:198;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_324x160";a:4:{s:4:"file";s:27:"restaurants19-2-324x160.jpg";s:5:"width";i:324;s:6:"height";i:160;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_324x235";a:4:{s:4:"file";s:27:"restaurants19-2-324x235.jpg";s:5:"width";i:324;s:6:"height";i:235;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_356x220";a:4:{s:4:"file";s:27:"restaurants19-2-356x220.jpg";s:5:"width";i:356;s:6:"height";i:220;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_356x364";a:4:{s:4:"file";s:27:"restaurants19-2-356x364.jpg";s:5:"width";i:356;s:6:"height";i:364;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_533x261";a:4:{s:4:"file";s:27:"restaurants19-2-533x261.jpg";s:5:"width";i:533;s:6:"height";i:261;s:9:"mime-type";s:10:"image/jpeg";}s:10:"td_534x462";a:4:{s:4:"file";s:27:"restaurants19-2-534x386.jpg";s:5:"width";i:534;s:6:"height";i:386;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}}" ["type"]=> string(11) "post_images" }