Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wp-statistics domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the cyr2lat domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the essential-addons-for-elementor-lite domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the translatepress-multilingual domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/s/serjpozw/wp-prog.ru/public_html/wp-includes/functions.php on line 6114 PHP - приемы - WP-prog

WP-prog

PHP – приемы

1. Как получить файлы из папки. Это может понадобиться, например, для автоматической загрузки картинок из папки в галерею
				
					<div class="slider doors-slider">
							<?php
							$directory = "img/slider1/";
							$images = glob($directory . "*.{jpg,JPG,png}", GLOB_BRACE);
							
							foreach ($images as $image) {
								$img = '<img decoding="async" class="slide" src="' . $image . '" alt="' . ltrim(str_replace('img/slider1/', '', substr($image, 0, -4)), ' 0123456789') . '">';
								echo $img;
							}
							?>
						</div>
				
			

2-й вариант. Понадобится в том случае, когда имена файлов имеют цифры в начале (123_image.img) и сортировка происходит некорректно

				
					<?php
function show_img($dir)
{
	$images = scandir('img/' . $dir);
	sort($images, SORT_NUMERIC);

	foreach ($images as $image) {
		if ($image != '.' && $image != '..') {
			$img = '<img decoding="async" class="slide" src="img/' . $dir . '/' . $image . '" alt="' . ltrim(str_replace('img/' . $dir . '/', '', substr($image, 0, -4)), ' 0123456789') . '">';
			echo $img;
		}
	}
}
?>