How to always display the latest image

Hi All,

I have a dynamic page filter issue to ask you all.

The dynamic page is setup whereby users can cycle through images.

When users go to a certain page on my site, I want them to always see the latest image and they can cycle back to the first if they so wish. However, what’s happening at the moment is that when they come to the page, the page always shows the first image and not the latest. Each image has a unique ID and I’ve added a filter so that it filters from last to first (or, at least I think it does).

Any assistance would be great.

Update:

I’m using code to allow users to cycle between the images which also allows them to jump the first and last images. I think this is causing the problem?

Here’s the code:

$w.onReady( function () {

$w(“#previous”).disable();
$w(“#next”).disable();
$w(“#last”).disable();
$w(“#first”).disable();

if (local.getItem(‘dynamicPageURLs’)) {
const dynamicPageURLs = local.getItem(‘dynamicPageURLs’).split(‘,’);
console.log(dynamicPageURLs.length)

const currentPage = ‘/’ + wixLocation.prefix + ‘/’ + wixLocation.path.join(‘/’);
const currentPageIndex = dynamicPageURLs.indexOf(currentPage);
console.log(currentPage, currentPageIndex)

if (currentPageIndex > 0) {
$w(“#next”).link = dynamicPageURLs[currentPageIndex - 1];
$w(“#next”).enable();
let dynamicPagesURLs = local.getItem(‘dynamicPageURLs’).split(‘,’);
const currentPage = ‘/’ + wixLocation.prefix + ‘/’ + wixLocation.path.join(‘/’);
let length = dynamicPagesURLs.length-1;
$w(“#last”).link = dynamicPagesURLs[0];
$w(“#last”).enable();

} 

if (currentPageIndex < dynamicPageURLs.length - 1) {
$w(“#previous”).link = dynamicPageURLs[currentPageIndex + 1];
$w(“#previous”).enable();
let dynamicPagesURLs = local.getItem(‘dynamicPageURLs’).split(‘,’);
const currentPage = ‘/’ + wixLocation.prefix + ‘/’ + wixLocation.path.join(‘/’);
let length = dynamicPagesURLs.length-1;
$w(“#first”).link = dynamicPagesURLs[length];
$w(“#first”).enable();
}
}
} );

I think this needs to somehow always display the newest item first. However, my coding skills are really bad and any help would be great!