Page 1 of 1

Using glob() function - help

Posted: Tue Apr 21, 2009 11:43 am
by ldexterldesign
Easy guys,

I'd like to get rid of the first element in this array (see script below). It outputs an initial list item I don't want, namely the filename

Code: Select all

..
referencing the the parent directory:

PHP

Code: Select all

       <?php
            // get template directory (wordpress)
            $templateDir = get_bloginfo(template_directory);
            // get current directory
            getcwd();
            // change to directory we want
            chdir('wp-content\themes\ldexterldesign\images\logos\accreditors\hoverOff');
            // make a variable of the path
            $cwd = getcwd();
            // get all the filenames
            $files = scandir($cwd);
            // count total files in directory
            $totalFiles = count($files);
            // get end directory from the $cwd
            $endDirectory = explode('\\', $templateDir);
            // spit out the filenames with img tag HTML
            echo '<ul id="accreditors">';
            for($i = 1; $i <= $totalFiles-1; $i++){
                echo '<li>';
                echo '<a href="#">';
                echo '<img src="';
                echo $templateDir;
                echo '/images/logos/accreditors/hoverOff/';
                echo $files[$i];
                echo '"/>';
                echo '</a>';
                echo '</li>';
                }
                echo '</ul>';
        ?>
HTML

Code: Select all

<ul id="accreditors">
[i]  <li><a href="#"><img src="http://localhost/wordpress/wp-content/themes/ldexterldesign/images/logos/accreditors/hoverOff/.."/></a></li>[/i]
  <li><a href="#"><img src="http://localhost/wordpress/wp-content/themes/ldexterldesign/images/logos/accreditors/hoverOff/ABBE.gif"/></a></li>
  <li><a href="#"><img src="http://localhost/wordpress/wp-content/themes/ldexterldesign/images/logos/accreditors/hoverOff/BRE.gif"/></a></li>
  <li><a href="#"><img src="http://localhost/wordpress/wp-content/themes/ldexterldesign/images/logos/accreditors/hoverOff/ECMK.gif"/></a></li>
  <li><a href="#"><img src="http://localhost/wordpress/wp-content/themes/ldexterldesign/images/logos/accreditors/hoverOff/IBG.gif"/></a></li>
  <li><a href="#"><img src="http://localhost/wordpress/wp-content/themes/ldexterldesign/images/logos/accreditors/hoverOff/thamesValley.gif"/></a></li>
</ul>
I'm keen to use the glob() function as @pickle kindly pointed out, but am at a loss as to how and where to implement it (even if it's the correct solution at all!)

Thanks to anyone that can help.

Cheers,
L

Re: Using glob() function - help

Posted: Wed Apr 22, 2009 8:02 am
by ldexterldesign
Well, I've made good use of array_shift() this morning anyway, which knocked the pesky initial array element off for me (.)

L