Support » Themes and Templates » foreach ( new DirectoryIterator($img_directory) as $item ) not working

  • Shirley Studebaker

    (@shirley-studebaker)


    Does anyone see anything wrong with this slideshow code for a template. Trying to read in files from an image folder for a slideshow. Gets hung up after <div id="myslides">

    See:

    Here is my test template (BTW I’m kind of new at WP template programming so tips are appreciated). Code is all tested and working outside of WP:

    <?php
    /* Template Name: Custom Interior Page */
    list($bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2, $bfa_ata['h_blogtitle'], $bfa_ata['h_posttitle']) = bfa_get_options();
    get_header();
    extract($bfa_ata);
    global $bfa_ata_postcount;
    ?>
    
    <script src="../../scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../scripts/jquery.cycle.lite.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    	$('#myslides').cycle({
    		fit: 1, pause: 1, timeout: 4000
    	});
    });
    </script>
    <style> #myslides { height:400px; width:600px; } </style>
    <div id="interior_wrapper">
    <?php
    
        global $post;
        $post_slug=$post->post_name;
    
    	$img_directory = '../../images/'.$post_slug;
    	// echo $directory;
    	// Styling for images
    	echo '<div id="myslides">';
    	foreach ( new DirectoryIterator($img_directory) as $item ) {
    		if ($item->isFile()) {
    			$path = $img_directory . '/' . $item;
    			echo '<img src="' . $path . '"/>';
    		}
    	}
    	echo '</div>';
    ?>	
    
    </div>
    <?php get_footer(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Shirley Studebaker

    (@shirley-studebaker)

    For some reason link didn’t come through. Here’s the page:

    Thread Starter Shirley Studebaker

    (@shirley-studebaker)

    Not sure why I can’t post the link to the page!

    If doesn’t come thru this time then maybe cuz I am using IP address.

    link is (with spaces added) 74 . 115 . 229 . 75 / kids-camp /

    Thread Starter Shirley Studebaker

    (@shirley-studebaker)

    Alright here’s the code again. Somehow it got pulled into the link. Sorry to be such a dweeb.

    <?php
    /* Template Name: Custom Interior Page */
    list($bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2, $bfa_ata['h_blogtitle'], $bfa_ata['h_posttitle']) = bfa_get_options();
    get_header();
    extract($bfa_ata);
    global $bfa_ata_postcount;
    ?>
    
    <script src="../../scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../scripts/jquery.cycle.lite.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    	$('#myslides').cycle({
    		fit: 1, pause: 1, timeout: 4000
    	});
    });
    </script>
    <style> #myslides { height:400px; width:600px; } </style>
    <div id="interior_wrapper">
    <?php
    
        global $post;
        $post_slug=$post->post_name;
    
    	$img_directory = '../../images/'.$post_slug;
    	// echo $directory;
    	// Styling for images
    	echo '<div id="myslides">';
    	foreach ( new DirectoryIterator($img_directory) as $item ) {
    		if ($item->isFile()) {
    			$path = $img_directory . '/' . $item;
    			echo '<img src="' . $path . '"/>';
    		}
    	}
    	echo '</div>';
    ?>	
    
    </div>
    <?php get_footer(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘foreach ( new DirectoryIterator($img_directory) as $item ) not working’ is closed to new replies.