Title: Loop Issue Foreach
Last modified: August 21, 2016

---

# Loop Issue Foreach

 *  Resolved [mak1wp](https://wordpress.org/support/users/mak1wp/)
 * (@mak1wp)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-foreach/)
 * Hello,
 * I’m having trouble with a loop that uses foreach.
 * I’m using SMOF (slightly modified options framework) to list an array of images
   which are placed into a flex slider.
 * Heres the old code which works…. (but the issue with this is, I dont know how
   to specify the image sizes)
 *     ```
       <?php
            $slides = $data['pingu_slider']; //get the slides array
   
       		foreach ($slides as $slide) {
       		echo 
   
       	'<li>
       	<a href="'. $slide['link']. ' ">
       	<img src="' . $slide['url' ] . '" />
       	</a>
   
       		<div class="flex-title">'.  $slide['title']. ' </div>
       		<div class="flex-caption">'. $slide['description']. ' </div> 
   
       		</li>';
       }
       ?>
       ```
   
 * Heres the new code, which will specify the image size, but it only shows the 
   first image.
 *     ```
       <div class="row">
             <div class="large-12 columns">
   
            <div id="slider" class="flexslider">
   
               <ul  class="slides">
   
       		<?php $loop = new WP_Query( array( 'pingu_slider' ) ); ?>
               <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
               <?php 
   
       	foreach ($loop as $loop) {	?> 
   
                               <li>
                                           <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'small-thumb' ); } ?>
   
                               </li>
   
                           <?php }endwhile; ?>
   
                       </ul>
                   </div>
       </div>
       ```
   
 * Many many thanks to anybody that can help.
 * Cheers

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [skim-](https://wordpress.org/support/users/skim-/)
 * (@skim-)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-foreach/#post-3983162)
 * You can **hack** this with an html width attribute on the image
 *     ```
       <?php
            $slides = $data['pingu_slider']; //get the slides array
   
       		foreach ($slides as $slide) {
       		echo 
   
       	'<li>
       	<a href="'. $slide['link']. ' ">
       	<img src="' . $slide['url' ] . '" width="400" />
       	</a>
   
       		<div class="flex-title">'.  $slide['title']. ' </div>
       		<div class="flex-caption">'. $slide['description']. ' </div> 
   
       		</li>';
       }
       ?>
       ```
   
 * Or your second code block can be edited like this ( if ‘pingu_slider’ is a post
   type ). Also have a look at [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)
   for how to structure arguments for WP_Query.
 *     ```
       <ul  class="slides">
   
               <?php $loop = new WP_Query( array( 'post_type' => 'pingu_slider' ) ); ?>
               <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                       <li>
                          <?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'small-thumb' ); } ?>
                       </li>
   
              </ul>
       ```
   
 *  Thread Starter [mak1wp](https://wordpress.org/support/users/mak1wp/)
 * (@mak1wp)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-foreach/#post-3983187)
 * Hey [@skim-](https://wordpress.org/support/users/skim-/)
 * Thanks a lot for your reply, really appreciated.
 * Unfortunately the second solution doesn’t seem to want to work. the pingu slider
   is an array set up in the options framework [http://aquagraphite.com/2011/11/smof-documentation/](http://aquagraphite.com/2011/11/smof-documentation/),
   it just wants to show the first image, then disappear completely (doesn’t work
   at all with post_type) 😐
 * I’m unable to use the first solution for this one. Thanks again though, I’ll 
   check out this WP_Query link you’ve posted.
 * Cheers.
 *  Thread Starter [mak1wp](https://wordpress.org/support/users/mak1wp/)
 * (@mak1wp)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-foreach/#post-3983388)
 * Looks like this isn’t a possibility.
 * Solution:
 * ACF – instead of using:
    $image[‘url’]
 * I’ve used
    $image[‘sizes’][‘thumbnail’]
 * SMOF – I’m not too sure how to create arrays and such. So instead of using the
   options framework to add a slide, I’ve done it via a custom post type – with 
   help from this link [http://wp.tutsplus.com/tutorials/create-a-responsive-slider-plugin-with-flexslider/](http://wp.tutsplus.com/tutorials/create-a-responsive-slider-plugin-with-flexslider/)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Loop Issue Foreach’ is closed to new replies.

## Tags

 * [foreach](https://wordpress.org/support/topic-tag/foreach/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [SMOF](https://wordpress.org/support/topic-tag/smof/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [mak1wp](https://wordpress.org/support/users/mak1wp/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/loop-issue-foreach/#post-3983388)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
