Skip to content

Instantly share code, notes, and snippets.

@subfighter3
Forked from a-barbieri/loop-per-pyetro.php
Created November 11, 2019 14:28
Show Gist options
  • Save subfighter3/36bec9ccec1da90f597a832a2a017e5b to your computer and use it in GitHub Desktop.
Save subfighter3/36bec9ccec1da90f597a832a2a017e5b to your computer and use it in GitHub Desktop.
Per Pyetro
<?php if (have_posts()): ?>
<ul id="image-data-list">
<?php while(have_posts()): the_post(); ?>
<li data-image-url="<?= your_post_image_url ?>"></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
document.addEventListener( 'DOMContentLoaded', function( event ) {
const imagesData = document.querySelectorAll('#image-data-list > li');
const imagesUrlList = [];
[...imagesData].forEach(image => {
const url = image.getAttribute("data-image-url");
if (url) {
imagesUrlList.push(url);
}
});
imagesUrlList.each(imageUrl => {
// load the imageUrl
});
});
$(document).ready(function() {
var imagesUrlList = [];
$("#image-list > li").each(function() {
var url = $(this).data("image-url");
if (url !== "" && url !== null) {
imagesUrlList.push(url);
}
});
imagesUrlList.each(imageUrl => {
// load the imageUrl
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment