Hello!
@anthonysalamin @vincent @webdev @QA_Brandon @Lux @PixelGeek @cyberdave @RileyJones @rileyrichter
I feel like i’m close, but still no cigar. I’m using this awesome code to get a href and title text from the next Collection Item in the collection (this works perfectly):
<script>
var Webflow = Webflow || [];
Webflow.push(function () {
var next_href = $('#post_list .w--current').parent().next().find('a').attr('href');
var previous_href = $('#post_list .w--current').parent().prev().find('a').attr('href');
var next_title = $('#post_list .w--current').parent().next().find('a').text();
var previous_title = $('#post_list .w--current').parent().prev().find('a').text();
//if last post in list
if(next_href == undefined) {
next_href = $('#post_list').children().children().first().find('a').attr('href');
$('#next_button').fadeOut(); //optional - remove if you want to loop to beginning
}
//if first post in list
if(previous_href == undefined) {
previous_href = $('#post_list').children().children().last().find('a').attr('href');
$('#previous_button').fadeOut(); //optional - remove if you want to loop to end
$('#blog_return').attr( "style", "display: flex !important;" );
}
//apply hrefs to next / previous buttons
$('#next_button').attr('href', next_href);
$('#previous_button').attr('href', previous_href);
$('#next_title').text(next_title);
$('#previous_title').text(previous_title);
});
</script>
I then want to add so it also get the image from the next Collection Item. But i seem to not be able to crack that part. The code i tried looks like this:
<script>
var Webflow = Webflow || [];
Webflow.push(function () {
var next_href = $('#post_list .w--current').parent().next().find('a').attr('href');
var previous_href = $('#post_list .w--current').parent().prev().find('a').attr('href');
var next_title = $('#post_list .w--current').parent().next().find('a').text();
var previous_title = $('#post_list .w--current').parent().prev().find('a').text();
var next_image = $('#post_list .w--current').parent().next().find('a').attr('img');
var previous_image = $('#post_list .w--current').parent().prev().find('a').attr('img');
//if last post in list
if(next_href == undefined) {
next_href = $('#post_list').children().children().first().find('a').attr('href');
$('#next_button').fadeOut(); //optional - remove if you want to loop to beginning
}
//if first post in list
if(previous_href == undefined) {
previous_href = $('#post_list').children().children().last().find('a').attr('href');
$('#previous_button').fadeOut(); //optional - remove if you want to loop to end
$('#blog_return').attr( "style", "display: flex !important;" );
}
//apply hrefs to next / previous buttons
$('#next_button').attr('href', next_href);
$('#previous_button').attr('href', previous_href);
$('#next_title').text(next_title);
$('#previous_title').text(previous_title);
$('#next_image').attr('img', next_image);
$('#previous_image').attr('img', previous_image);
});
</script>
(Read-only link below).
So on this page, all the way down at the bottom, there is an image behind the “Next” text. I want that to be the ‘Thumbnail Image’ from the next item in the collection.
Hope this makes any sense! Having this would make my day! Thank you for your help.