わかりました。私はphpにかなり慣れていないので、私の質問は信じられないほどばかげているかもしれませんが、考えられるすべての組み合わせを試しましたが、これを正しく機能させることができません。
空のギャラリーにメッセージがまったく表示されないか、画像が含まれているかどうかに関係なく、すべてのギャラリーに3回表示されます。
サムネイルの周囲が最も望ましいものではないことは知っていますが、自動画像のトリミングの周囲でサムネイルを作成しようとしましたが、それを一生機能させることができませんでした。
私の主な関心事は空のギャラリーメッセージですが、信頼できる画像トリミングスニペットを組み込んでより良いサムネイルを作成するのを手伝ってくれるなら..してください:)
function lightbox_display($dir_to_search, $rel){
$image_dir = $dir_to_search;
$dir_to_search = scandir($dir_to_search);
$image_exts = array('gif', 'jpg', 'jpeg', 'png');
$excluded_filename = '_t';
foreach ($dir_to_search as $image_file){
$dot = strrpos($image_file, '.');
$filename = substr($image_file, 0, $dot);
$filetype = substr($image_file, $dot+1);
$thumbnail_file = strrpos($filename, $excluded_filename);
if ((!$thumbnail_file) and array_search($filetype, $image_exts) !== false){
echo "<a href='".$image_dir.$image_file."' rel='".$rel."'>
<img src='".$image_dir.$image_file."' alt='".$filename."' width='100' height='80' title='' border='none'/>
</a>"."\n";
} else {
echo 'Currently there are no machines available for sale, please check back with us soon.';
}
}
}
更新されたphpコーディング:
$ imagesFoundに配列を追加して、サーバー側のフォルダーが含まれる可能性を排除してみました。
function lightbox_display($dir_to_search, $rel){
$image_dir = $dir_to_search;
$dir_to_search = scandir($dir_to_search);
$image_exts = array('gif', 'jpg', 'jpeg', 'png');
$excluded_filename = '_t';
$imagesFound = array('gif', 'jpg', 'jpeg', 'png') && 0;
foreach ($dir_to_search as $image_file){
$dot = strrpos($image_file, '.');
$filename = substr($image_file, 0, $dot);
$filetype = substr($image_file, $dot+1);
$thumbnail_file = strrpos($filename, $excluded_filename);
if ((!$thumbnail_file) && array_search($filetype, $image_exts) !== false) {
$imagesFound++;
echo "<a href='$image_dir$image_file' rel='$rel'>
<img src='$image_dir$image_file' alt='$filename' width='100' height='80' title='' border='none'/>
</a>\n";
}
if ((0 === $imagesFound) !== true){
echo 'Currently there are no machines available for sale, please check back with us soon.';
}
}
}