Hello again.
On my site, if the user is logged in, the sort works for the shortcode-generated list of items. However, if the user is not logged in, it does not work. How do I fix it?
This is my site:
https://blmohp.sewanee.edu/page/people
This is my code:
<div class="preview-block clearfix">[items item_set=8 num=0 sort=foaf:lastName]</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', async () => {
const items = document.querySelectorAll('.resource.item');
for(let item of items) {
const itemThumb = item.querySelector('.resource.item a').firstChild;
itemThumb.classList.add('item-thumbnail');
// Extract the item ID from the title link
const idMatch = item.querySelector('h4 a').getAttribute('href').match(/\/item\/(\d+)/);
if (idMatch) {
const itemID = idMatch[1];
// Fetch Media-IDs for audio-visual documents asynchronously
let mediaID;
try {
const response = await fetch(`/api/media?item=${itemID}`);
const mediaItems = await response.json();
for(let mediaItem of mediaItems) {
if (mediaItem['o:ingester'] === 'youtube') {
mediaID = mediaItem['o:id'];
break;
}
}
} catch (error) {
console.error('Failed to fetch media items:', error);
// Handle error appropriately
}
if (mediaID) {
// Create Button See the Interview
const buttonSee = document.createElement('a');
buttonSee.setAttribute('href', '/media/' + mediaID);
buttonSee.classList.add('button-see');
buttonSee.innerHTML = '<img src="https://omeka-s.sewanee.edu/files/asset/c3363c21b14027aaa6c0f7a9d07580da4f8359c7.png" alt="Button See the Interview">';
// If a media item with a YouTube ingester was found, append the See the Interview button
const itemButtons = item.querySelector('.item-buttons') || document.createElement('div');
itemButtons.classList.add('item-buttons');
itemButtons.appendChild(buttonSee);
item.appendChild(itemButtons);
}
// Create Button Learn More
const buttonLearn = document.createElement('a');
buttonLearn.setAttribute('href', '/item/' + itemID);
buttonLearn.classList.add('button-learn');
buttonLearn.innerHTML = '<img src="https://omeka-s.sewanee.edu/files/asset/40ab43f8a04a70f61edd9cb5dfa1afb2f232f52e.png" alt="Button Learn More">';
// Append Learn More button regardless of the mediaID existence
const itemButtons = item.querySelector('.item-buttons') || document.createElement('div');
itemButtons.classList.add('item-buttons');
itemButtons.appendChild(buttonLearn);
item.appendChild(itemButtons);
}
}
});
</script>