Loading news…
const NEWS_API_URL = '/wp-admin/admin-ajax.php?action=fetch_news';
async function fetchNews() { const container = document.getElementById('news-container'); container.innerHTML = '
Loading news...
';
try { const response = await fetch(NEWS_API_URL);
if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); }
const data = await response.json();
if (data.success && data.data.articles.length > 0) { container.innerHTML = ''; data.data.articles.forEach(article => { const newsCard = document.createElement('div'); newsCard.className = 'news-card';
newsCard.innerHTML = `
`;
container.appendChild(newsCard); }); } else { container.innerHTML = '
No news available at the moment.
'; } } catch (error) { console.error('Error fetching news:', error); container.innerHTML = `
Error: ${error.message}
`; } }
// Fetch news on page load
fetchNews();