I need to create a previous and next navigation in one folder using a structure like page 1 page 2 etc My current not-working code is the following:
<?php
$search_dir = "gallery";
$images = glob("$search_dir/*.jpg");
sort($images);
$current = 2;
$prev_img = $images[$current - 1];
$next_img = $images[$current + 1];
// Image selection and display:
//display first image
if (count($images) > 0) { // make sure at least one image exists
$img = $images[0]; // first image
?>
<ul>
<li><a href="<?php echo $prev_img; ?>">Previous</a></li>
<li><a href="<?php echo $next_img; ?>">Next</a></li>
</ul>
<figure><img src="<?php echo $img; ?>" alt="<?php echo $img; ?>"></figure>
<?php
} else {
echo 'error';
}
?>