Loading sitemap…
#wp-sitemap {
font-family: Arial, sans-serif;
padding: 16px;
}
#wp-sitemap ul {
list-style: none;
padding-left: 20px;
margin: 8px 0;
}
#wp-sitemap li {
margin: 6px 0;
}
#wp-sitemap a {
text-decoration: none;
color: #0066cc;
}
#wp-sitemap a:hover {
text-decoration: underline;
}
document.addEventListener(“DOMContentLoaded”, function () {
const sitemap = document.getElementById(“wp-sitemap”);
fetch(“/wp-json/wp/v2/pages?per_page=100&_fields=id,parent,link,title,menu_order”)
.then(response => response.json())
.then(pages => {
if (!Array.isArray(pages) || pages.length === 0) {
sitemap.innerHTML = “No pages found.”;
return;
}
const grouped = {};
pages.forEach(page => {
const parent = page.parent || 0;
if (!grouped[parent]) grouped[parent] = [];
grouped[parent].push(page);
});
Object.keys(grouped).forEach(key => {
grouped[key].sort((a, b) => {
return (a.menu_order || 0) – (b.menu_order || 0);
});
});
function buildList(parentId) {
if (!grouped[parentId]) return “”;
let html = “- “;
grouped[parentId].forEach(page => {
html += “
- “; html += `${page.title.rendered}`; html += buildList(page.id); html += “ “; }); html += “
