Nederlands
Loading may take 15 seconds
(function() {
var domain = “warewijnstok.thevine.name” //domain name
var categoryId = 573; //catigory id
var container = document.getElementById(‘category-pages’);
var allPages = []; // To store all fetched pagesfunction fetchPages(pageNumber) {
var cacheBuster = new Date().getTime(); // Generate a unique timestamp
fetch(‘https://’ + domain + ‘/wp-json/wp/v2/pages?categories=’ + categoryId + ‘&per_page=100&page=’ + pageNumber + ‘&cache_buster=’ + cacheBuster) // tell the suver to get the public jason
.then(function(response) {
return response.json(); //returen the reponce as a json obgect
})
.then(function(pages) {
if (pages.length > 0) { //checks for more pages as you can only reqest up to 100 at a time
allPages = allPages.concat(pages);
allPages.sort(function(a, b) {// sort the list apibdicaly
return a.title.rendered.localeCompare(b.title.rendered);
});
var html = ‘
‘;//assembale the html string
allPages.forEach(function(page) {
var permalink = page.link;
html += ‘- ‘ + page.title.rendered + ‘
‘;
});
html += ‘
‘;
container.innerHTML = html;fetchPages(pageNumber + 1);
} else {
allPages.sort(function(a, b) {// sort the list apibdicaly
return a.title.rendered.localeCompare(b.title.rendered);
});var html = ‘
‘;//assembale the html string
allPages.forEach(function(page) {
var permalink = page.link;
html += ‘- ‘ + page.title.rendered + ‘
‘;
});
html += ‘
‘;
container.innerHTML = html;// add html string to the html contaner at the top
}
});
}
fetchPages(1); //exicuse code
})();