PHP Code:
<?php
// split the path in two since I use the second half later
$doc_root = '/home/cPanelUsername/public_html' ;
$image_dir = '/images/goats/' ;
$image_dir_path = $doc_root . $image_dir ;
// open a handle to the directory
$dir_handle = opendir( $image_dir_path );
// initialize counter and the display string
$count = 0 ;
$display = '' ;
// read one file name at a time
while( $filename = readdir($dir_handle)){
// just the files that match your pattern
if( preg_match( '/$[a-z0-9]{4}_th\.jpg$/' , $filename ) ){
// add to display string...can add 'Alt' tag
$display .= " <img src='$image_dir$filename' /> " ;
$count++ ;
// every 10 images, reset counter and add <br /> tag
if( $count % 10 == 0 ){
$count=0;
$display .= "<br />";
}
}
}
// clean up
closedir( $dir_handle );
echo $display ;
?>