{"id":82,"date":"2026-04-10T14:47:27","date_gmt":"2026-04-10T14:47:27","guid":{"rendered":"https:\/\/louthlgfa.ie\/?page_id=82"},"modified":"2026-04-10T16:37:07","modified_gmt":"2026-04-10T16:37:07","slug":"league-tables","status":"publish","type":"page","link":"https:\/\/louthlgfa.ie\/?page_id=82","title":{"rendered":"League Tables"},"content":{"rendered":"\n<div id=\"leagueTablesPage\" style=\"font-family:Arial, sans-serif;\">\n    <div id=\"loadingSpinner\" style=\"text-align:center; padding:20px;\">\n        <div style=\"\n            border: 6px solid #f3f3f3;\n            border-top: 6px solid #3498db;\n            border-radius: 50%;\n            width: 40px;\n            height: 40px;\n            margin: 0 auto;\n            animation: spin 1s linear infinite;\n        \"><\/div>\n        <p style=\"margin-top:10px; font-size:16px;\">Retrieving league tables\u2026 this might take a minute<\/p>\n    <\/div>\n<\/div>\n\n<style>\n@keyframes spin {\n    0% { transform: rotate(0deg); }\n    100% { transform: rotate(360deg); }\n}\n<\/style>\n\n<script>\n(async () => {\n    const apiKey = \"foir_prod_NDtiJNVWyQpxRRujIXMrCOZntNaqZfflFjihYbiLtqilV\";\n    const ownerId = \"0e2e84a8-2d94-dc94-d574-9d44d4c15395\";\n\n    const out = document.getElementById(\"leagueTablesPage\");\n    const spinner = document.getElementById(\"loadingSpinner\");\n\n    \/\/ Fetch fixtures page-by-page until we have enough 2026 competitions\n    async function fetchFixturesFor2026() {\n        let page = 0;\n        let totalPages = 1;\n        const compIds = new Set();\n\n        while (page < totalPages) {\n            const url = `https:\/\/api.foireann.ie\/open-data\/v1\/fixtures?size=200&#038;page=${page}`;\n\n            const res = await fetch(url, {\n                headers: {\n                    \"Authorization\": \"Bearer \" + apiKey,\n                    \"Accept\": \"application\/json\"\n                }\n            });\n\n            const json = await res.json();\n            const fixtures = json.data || [];\n\n            fixtures.forEach(f => {\n                if (!f.startDate) return;\n                const year = new Date(f.startDate).getFullYear();\n                if (year === 2026 && f.competition?.id) {\n                    compIds.add(f.competition.id.trim());\n                }\n            });\n\n            totalPages = json.page?.totalPages || 1;\n            page++;\n\n            \/\/ Stop early if we already found enough competitions\n            if (compIds.size >= 20) break;\n        }\n\n        return [...compIds];\n    }\n\n    \/\/ Extract ALL league tables from ALL divisions\/leagues\n    function findAllLeagueTables(comp) {\n        const tables = [];\n\n        if (!comp.divisions) return tables;\n\n        comp.divisions.forEach(div => {\n            if (!div.leagues) return;\n\n            div.leagues.forEach(league => {\n                if (league.teams && league.teams.length > 0) {\n                    tables.push({\n                        divisionName: div.name || \"Division\",\n                        leagueName: league.name || \"League\",\n                        teams: league.teams\n                    });\n                }\n            });\n        });\n\n        return tables;\n    }\n\n    try {\n        \/\/ Step 1: Get competition IDs with fixtures in 2026\n        const compIds = await fetchFixturesFor2026();\n\n        \/\/ Step 2: Fetch metadata for each competition\n        const competitions = [];\n        for (const compId of compIds) {\n            const url = `https:\/\/api.foireann.ie\/open-data\/v1\/competitions?id=${compId}`;\n            const res = await fetch(url, {\n                headers: {\n                    \"Authorization\": \"Bearer \" + apiKey,\n                    \"Accept\": \"application\/json\"\n                }\n            });\n            const json = await res.json();\n            if (json.data && json.data.length > 0) {\n                competitions.push(json.data[0]);\n            }\n        }\n\n        \/\/ Step 3: Filter to competitions with league tables\n        const compsWithTables = competitions\n            .map(c => ({\n                comp: c,\n                tables: findAllLeagueTables(c)\n            }))\n            .filter(x =>\n                x.comp.owner?.id === ownerId &&\n                x.tables.length > 0\n            );\n\n        spinner.remove();\n\n        if (compsWithTables.length === 0) {\n            out.innerHTML = \"<p>No league tables available for competitions with fixtures in 2026.<\/p>\";\n            return;\n        }\n\n        \/\/ Step 4: Sort alphabetically\n        compsWithTables.sort((a, b) => a.comp.name.localeCompare(b.comp.name));\n\n        \/\/ Step 5: Build HTML\n        let html = `<h2>Louth LGFA League Tables (2026)<\/h2>`;\n\n        compsWithTables.forEach(({ comp, tables }) => {\n            html += `\n                <details style=\"margin-bottom:20px;\">\n                    <summary style=\"cursor:pointer; font-size:18px; font-weight:bold;\">\n                        ${comp.name}\n                    <\/summary>\n                    <div style=\"margin-top:10px;\">\n            `;\n\n            tables.forEach((tbl, index) => {\n                html += `\n                    <h4>${tbl.divisionName} \u2013 ${tbl.leagueName}<\/h4>\n                    <table style=\"width:100%; border-collapse:collapse; margin-bottom:20px;\">\n                        <thead>\n                            <tr>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">Rank<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">Team<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">P<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">W<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">D<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">L<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">PF<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">PA<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">PD<\/th>\n                                <th style=\"border:1px solid #ccc; padding:6px;\">Pts<\/th>\n                            <\/tr>\n                        <\/thead>\n                        <tbody>\n                            ${tbl.teams.map(t => `\n                                <tr>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.rank}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.name}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.played}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.won}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.drawn}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.lost}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.pointsFor}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.pointsAgainst}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.pointsDifference}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${t.totalPoints}<\/td>\n                                <\/tr>\n                            `).join(\"\")}\n                        <\/tbody>\n                    <\/table>\n                `;\n            });\n\n            html += `<\/div><\/details>`;\n        });\n\n        out.innerHTML = html;\n\n    } catch (err) {\n        spinner.remove();\n        out.textContent = \"Error loading league tables: \" + err;\n    }\n})();\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>Retrieving league tables\u2026 this might take a minute<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-82","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/82","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=82"}],"version-history":[{"count":6,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/82\/revisions"}],"predecessor-version":[{"id":89,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/82\/revisions\/89"}],"wp:attachment":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}