{"id":96,"date":"2026-04-11T20:46:35","date_gmt":"2026-04-11T20:46:35","guid":{"rendered":"https:\/\/louthlgfa.ie\/?page_id=96"},"modified":"2026-04-13T08:40:44","modified_gmt":"2026-04-13T08:40:44","slug":"front-page-v2","status":"publish","type":"page","link":"https:\/\/louthlgfa.ie\/?page_id=96","title":{"rendered":"Front Page V2"},"content":{"rendered":"\n<p class=\"has-medium-font-size\"><strong>Fixtures, Results &amp; Standings<\/strong><\/p>\n\n\n\n<div style=\"margin-bottom:15px;\">\n    <input \n        id=\"teamSearch\" \n        type=\"text\" \n        placeholder=\"Search by team name\u2026\" \n        style=\"width:100%; padding:10px; font-size:16px; border:1px solid #ccc; border-radius:4px;\"\n    >\n<\/div>\n\n<div id=\"multiCompDashboard\">Loading competitions\u2026<\/div>\n\n<script>\n\/\/ Wait until WordPress actually inserts the HTML element\nfunction waitForElement(id, callback) {\n    const el = document.getElementById(id);\n    if (el) {\n        callback(el);\n    } else {\n        setTimeout(() => waitForElement(id, callback), 50);\n    }\n}\n\nwaitForElement(\"multiCompDashboard\", function (dashboardEl) {\n\n    (async () => {\n        const apiKey = \"foir_prod_NDtiJNVWyQpxRRujIXMrCOZntNaqZfflFjihYbiLtqilV\";\n        const ownerId = \"0e2e84a8-2d94-dc94-d574-9d44d4c15395\";\n\n        const url = `https:\/\/api.foireann.ie\/open-data\/v1\/fixtures?size=500`;\n\n        const response = await fetch(url, {\n            headers: {\n                \"Authorization\": \"Bearer \" + apiKey,\n                \"Accept\": \"application\/json\"\n            }\n        });\n\n        const json = await response.json();\n        let fixtures = json.data || [];\n\n        \/\/ Restrict to this owner ID\n        fixtures = fixtures.filter(f => f.owner?.id === ownerId);\n\n        \/\/ Restrict to 2026 only\n        fixtures = fixtures.filter(f => {\n            if (!f.startDate) return false;\n            return new Date(f.startDate).getFullYear() === 2026;\n        });\n\n        if (fixtures.length === 0) {\n            dashboardEl.innerHTML = \"<p>No competitions found for 2026.<\/p>\";\n            return;\n        }\n\n        \/\/ Group by competition\n        const comps = {};\n        fixtures.forEach(f => {\n            const compId = f.competition?.id || \"unknown\";\n            const compName = f.competition?.name || \"Unknown Competition\";\n\n            if (!comps[compId]) {\n                comps[compId] = {\n                    name: compName,\n                    fixtures: [],\n                    tables: []\n                };\n            }\n            comps[compId].fixtures.push(f);\n        });\n\n        \/\/ Fetch league tables for each competition\n        async function fetchLeagueTables(compId) {\n            const url = `https:\/\/api.foireann.ie\/open-data\/v1\/competitions?id=${compId}`;\n\n            try {\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 comp = json.data?.[0];\n                if (!comp) return [];\n\n                const tables = [];\n\n                if (comp.divisions) {\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\n                return tables;\n\n            } catch (err) {\n                console.warn(\"Failed to fetch league tables for\", compId, err);\n                return [];\n            }\n        }\n\n        \/\/ Fetch tables for all competitions in parallel\n        const compIds = Object.keys(comps);\n        const tableResults = await Promise.all(\n            compIds.map(id => fetchLeagueTables(id))\n        );\n\n        compIds.forEach((id, index) => {\n            comps[id].tables = tableResults[index] || [];\n        });\n\n        \/\/ Sort competitions alphabetically\n        const sortedCompIds = compIds.sort((a, b) =>\n            comps[a].name.localeCompare(comps[b].name)\n        );\n\n        let html = `<h2>Louth LGFA Competitions (2026)<\/h2>`;\n\n        \/\/ Build UI\n        for (const compId of sortedCompIds) {\n            const comp = comps[compId];\n\n            \/\/ Correct result detection\n            const results = comp.fixtures.filter(f => {\n                return (\n                    f.isResult === true ||\n                    f.homeTeam?.goals !== undefined ||\n                    f.homeTeam?.points !== undefined ||\n                    f.awayTeam?.goals !== undefined ||\n                    f.awayTeam?.points !== undefined\n                );\n            });\n\n            \/\/ Fixtures = no score recorded\n            const upcoming = comp.fixtures.filter(f => {\n                return !(\n                    f.isResult === true ||\n                    f.homeTeam?.goals !== undefined ||\n                    f.homeTeam?.points !== undefined ||\n                    f.awayTeam?.goals !== undefined ||\n                    f.awayTeam?.points !== undefined\n                );\n            });\n\n            \/\/ Sort results newest \u2192 oldest\n            results.sort((a, b) => new Date(b.startDate) - new Date(a.startDate));\n\n            \/\/ Sort fixtures oldest \u2192 newest\n            upcoming.sort((a, b) => new Date(a.startDate) - new Date(b.startDate));\n\n            \/\/ Build Results HTML\n            const resultsHtml = results.length === 0 ? \"<p>No results available.<\/p>\" : `\n                <table style=\"width:100%; border-collapse:collapse; margin-top:10px;\">\n                    <thead>\n                        <tr>\n                            <th style=\"border:1px solid #ccc; padding:6px;\">Date<\/th>\n                            <th style=\"border:1px solid #ccc; padding:6px;\">Home<\/th>\n                            <th style=\"border:1px solid #ccc; padding:6px;\">H Score<\/th>\n                            <th style=\"border:1px solid #ccc; padding:6px;\">Away<\/th>\n                            <th style=\"border:1px solid #ccc; padding:6px;\">A Score<\/th>\n                        <\/tr>\n                    <\/thead>\n                    <tbody>\n                        ${results.map(f => {\n                            const dt = new Date(f.startDate);\n                            const formatted = dt.toLocaleString(\"en-GB\", {\n                                day: \"2-digit\",\n                                month: \"2-digit\",\n                                year: \"2-digit\",\n                                hour: \"2-digit\",\n                                minute: \"2-digit\"\n                            });\n\n                            const homeScore = `${f.homeTeam?.goals ?? 0}-${f.homeTeam?.points ?? 0}`;\n                            const awayScore = `${f.awayTeam?.goals ?? 0}-${f.awayTeam?.points ?? 0}`;\n\n                            return `\n                                <tr class=\"rowItem\">\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${formatted}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${f.homeTeam?.name || \"\"}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${homeScore}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${f.awayTeam?.name || \"\"}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${awayScore}<\/td>\n                                <\/tr>\n                            `;\n                        }).join(\"\")}\n                    <\/tbody>\n                <\/table>\n            `;\n\n            \/\/ Build Fixtures HTML\n            const fixturesHtml = upcoming.length === 0 ? \"<p>No upcoming fixtures.<\/p>\" : `\n                <table style=\"width:100%; border-collapse:collapse; margin-top:10px;\">\n                    <thead>\n                        <tr>\n                            <th style=\"border:1px solid #ccc; padding:6px;\">Date<\/th>\n                            <th style=\"border:1px solid #ccc; padding:6px;\">Home<\/th>\n                            <th style=\"border:1px solid #ccc; padding:6px;\">Away<\/th>\n                        <\/tr>\n                    <\/thead>\n                    <tbody>\n                        ${upcoming.map(f => {\n                            const dt = new Date(f.startDate);\n                            const formatted = dt.toLocaleString(\"en-GB\", {\n                                day: \"2-digit\",\n                                month: \"2-digit\",\n                                year: \"2-digit\",\n                                hour: \"2-digit\",\n                                minute: \"2-digit\"\n                            });\n\n                            return `\n                                <tr class=\"rowItem\">\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${formatted}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${f.homeTeam?.name || \"\"}<\/td>\n                                    <td style=\"border:1px solid #ccc; padding:6px;\">${f.awayTeam?.name || \"\"}<\/td>\n                                <\/tr>\n                            `;\n                        }).join(\"\")}\n                    <\/tbody>\n                <\/table>\n            `;\n\n            \/\/ Build Standings HTML\n            const tables = comp.tables;\n            const standingsHtml = tables.length === 0 ? \"<p>No standings available.<\/p>\" : `\n                ${tables.map(tbl => `\n                    <h4 style=\"margin-top:15px;\">${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                `).join(\"\")}\n            `;\n\n            \/\/ Add competition block\n            html += `\n                <details class=\"compBlock\" style=\"margin-bottom:20px;\">\n                    <summary style=\"cursor:pointer; font-size:18px; font-weight:bold;\">\n                        ${comp.name}\n                    <\/summary>\n\n                    <div style=\"margin-top:10px;\">\n\n                        <p style=\"font-style:italic; margin-bottom:8px;\">Click to show\/hide<\/p>\n\n                        <button class=\"btnShow\" data-target=\"results-${compId}\" \n                            style=\"margin-right:10px; padding:6px 12px; cursor:pointer;\">\n                            Results\n                        <\/button>\n\n                        <button class=\"btnShow\" data-target=\"fixtures-${compId}\" \n                            style=\"margin-right:10px; padding:6px 12px; cursor:pointer;\">\n                            Fixtures\n                        <\/button>\n\n                        <button class=\"btnShow\" data-target=\"standings-${compId}\" \n                            style=\"padding:6px 12px; cursor:pointer;\">\n                            Standings\n                        <\/button>\n\n                        <div id=\"results-${compId}\" style=\"display:none;\">\n                            ${resultsHtml}\n                        <\/div>\n\n                        <div id=\"fixtures-${compId}\" style=\"display:none;\">\n                            ${fixturesHtml}\n                        <\/div>\n\n                        <div id=\"standings-${compId}\" style=\"display:none;\">\n                            ${standingsHtml}\n                        <\/div>\n\n                    <\/div>\n                <\/details>\n            `;\n        }\n\n        dashboardEl.innerHTML = html;\n\n        \/\/ BUTTON SHOW\/HIDE LOGIC\n        document.querySelectorAll(\".btnShow\").forEach(btn => {\n            btn.addEventListener(\"click\", () => {\n                const target = document.getElementById(btn.dataset.target);\n                target.style.display = target.style.display === \"none\" ? \"block\" : \"none\";\n            });\n        });\n\n        \/\/ SEARCH FILTER\n        const searchInput = document.getElementById(\"teamSearch\");\n        searchInput.addEventListener(\"input\", function () {\n            const term = this.value.toLowerCase();\n\n            document.querySelectorAll(\".compBlock\").forEach(block => {\n                let match = false;\n\n                block.querySelectorAll(\".rowItem\").forEach(row => {\n                    const text = row.innerText.toLowerCase();\n                    if (text.includes(term)) {\n                        row.style.display = \"\";\n                        match = true;\n                    } else {\n                        row.style.display = \"none\";\n                    }\n                });\n\n                block.style.display = match ? \"\" : \"none\";\n            });\n        });\n\n    })();\n\n});\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>Fixtures, Results &amp; Standings Loading competitions\u2026<\/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-96","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/96","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=96"}],"version-history":[{"count":11,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/96\/revisions"}],"predecessor-version":[{"id":106,"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=\/wp\/v2\/pages\/96\/revisions\/106"}],"wp:attachment":[{"href":"https:\/\/louthlgfa.ie\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}