Good afternoon everyone

There is a script that displays images from the specified folder, it copes well with this, but in this folder there are two types of images, a preview and an original, and they need to be displayed separately, you can help to separate them and display them

Previews start with thumb1.jpg, Original with page1.jpg

I need to display a gallery, like this:

<ul> ... <li><a href="page1.jpg"><img src="thumb1.jpg" alt="" /></a></li> <li><a href="page2.jpg"><img src="thumb2.jpg" alt="" /></a></li> <li><a href="page3.jpg"><img src="thumb3.jpg" alt="" /></a></li> ... </ul> 

Script itself

 $directory = './wp-content/plugins/real3d-flipbook/books/flipbook1'; //Π½Π°Π·Π²Π°Π½ΠΈΠ΅ ΠΏΠ°ΠΏΠΊΠΈ с изобраТСниями $allowed_types = array( 'jpg', 'jpeg', 'gif', 'png' ); //Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½Ρ‹Π΅ Ρ‚ΠΈΠΏΡ‹ ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΉ $file_parts = array(); $ext = ''; $title = ''; $i = 0; //ΠΏΡ€ΠΎΠ±ΡƒΠ΅ΠΌ ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΡŒ ΠΏΠ°ΠΏΠΊΡƒ $dir_handle = @opendir($directory) or die("There is an error with your image directory!"); while ($file = readdir($dir_handle)) //поиск ΠΏΠΎ Ρ„Π°ΠΉΠ»Π°ΠΌ { if ($file == '.' || $file == '..') continue; //ΠΏΡ€ΠΎΠΏΡƒΡΡ‚ΠΈΡ‚ΡŒ ссылки Π½Π° Π΄Ρ€ΡƒΠ³ΠΈΠ΅ ΠΏΠ°ΠΏΠΊΠΈ $file_parts = explode('.', $file); //Ρ€Π°Π·Π΄Π΅Π»ΠΈΡ‚ΡŒ имя Ρ„Π°ΠΉΠ»Π° ΠΈ ΠΏΠΎΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π΅Π³ΠΎ Π² массив $ext = strtolower(array_pop($file_parts)); //послСдний элСмСнСт - это Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ if (in_array($ext, $allowed_types)) { echo ' <img width="900" height="600" src="' . $directory . '/' . $file . '" class="attachment-slider wp-post-image" alt="img" title="img" />'; $i++; } } closedir($dir_handle); //Π·Π°ΠΊΡ€Ρ‹Ρ‚ΡŒ ΠΏΠ°ΠΏΠΊΡƒ 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

1 answer 1

So, what's the problem? Check the file name before displaying. For example, to display all pictures, excluding previews, in your case, add:

 while ($file = readdir($dir_handle)) //поиск ΠΏΠΎ Ρ„Π°ΠΉΠ»Π°ΠΌ { if (preg_match('/^thumb/', $file)) { //ΠΏΡ€Π΅Π²ΡŒΡŽ пропускаСм continue; } 

Or so:

 if ($file=='.' || $file == '..' || preg_match('/^thumb/', $file)) continue; 

Conditions do as you need.