From 46461be818d5de9cc6902df9505e4a0b1c6ced2a Mon Sep 17 00:00:00 2001 From: Hannes Heute <5753419+haheute@users.noreply.github.com> Date: Wed, 4 Jan 2023 14:25:33 +0100 Subject: [PATCH] improve previous / next function in photo gallery --- mod/photos.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index a1aebfac66..2f9c5ca310 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -937,11 +937,17 @@ function photos_content(App $a) $nxt = null; foreach ($prvnxt as $z => $entry) { if ($entry['resource-id'] == $ph[0]['resource-id']) { - $prv = $z - 1; - $nxt = $z + 1; + $prv = ($order_field === 'created') ? ($z - 1) : ($z + 1); + $nxt = ($order_field === 'created') ? ($z + 1) : ($z - 1); if ($prv < 0) { $prv = count($prvnxt) - 1; } + if ($nxt < 0) { + $nxt = count($prvnxt) - 1; + } + if ($prv >= count($prvnxt)) { + $prv = 0; + } if ($nxt >= count($prvnxt)) { $nxt = 0; } -- 2.39.5