Widget:UPDateOnline: Difference between revisions
Appearance
Created page with "<includeonly> <div id="update-online-news" style=" margin: 20px 0; padding: 25px; border: 1px solid #ddd; border-radius: 8px; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.08); "> <!-- Heading --> <div style=" font-family:'Playfair Display',Georgia,serif; font-size:180%; font-weight:bold; margin-bottom:15px; "> UPDate Online </div> <!-- Loading message --> <div id="update-onl..." |
No edit summary |
||
| Line 1: | Line 1: | ||
<includeonly> | <includeonly> | ||
<div | <div class="your-news-class" id="update-online-news"> | ||
"> | |||
<div id="update-online-loading"> | <div id="update-online-loading"> | ||
Loading latest news... | Loading latest news... | ||
</div> | </div> | ||
<div id="update-online-content" style="display:none;"> | <div id="update-online-content" style="display:none;"> | ||
<div class="update-online-date" id="update-online-date"></div> | |||
<div | |||
< | <h2 class="update-online-title" id="update-online-title"></h2> | ||
<div class="update-online-excerpt" id="update-online-excerpt"></div> | |||
<div | |||
< | <a class="update-online-link" | ||
id="update-online-link" | |||
href=" | href="" | ||
target="_blank" | target="_blank" | ||
rel="noopener noreferrer | rel="noopener noreferrer"> | ||
Read more → | Read more → | ||
</a> | </a> | ||
</div> | </div> | ||
| Line 89: | Line 29: | ||
(function () { | (function () { | ||
fetch( | |||
'https://upd.edu.ph/wp-json/wp/v2/posts?categories=4&per_page=1' | 'https://upd.edu.ph/wp-json/wp/v2/posts?categories=4&per_page=1' | ||
) | |||
.then(function (response) { | |||
return response.json(); | |||
}) | |||
.then(function (posts) { | |||
if (!posts || !posts.length) { | |||
throw new Error('No article found'); | |||
} | |||
var post = posts[0]; | |||
. | /* Title */ | ||
document.getElementById('update-online-title').innerHTML = | |||
post.title.rendered; | |||
/* Excerpt */ | |||
document.getElementById('update-online-excerpt').innerHTML = | |||
post.excerpt.rendered; | |||
/* Article URL */ | |||
document.getElementById('update-online-link').href = | |||
post.link; | |||
/* Date */ | |||
var date = new Date(post.date); | |||
document.getElementById('update-online-date').textContent = | |||
date.toLocaleDateString('en-US', { | |||
year: 'numeric', | |||
month: 'long', | |||
day: 'numeric' | |||
}); | |||
/* Show article */ | |||
document.getElementById('update-online-loading').style.display = | |||
'none'; | |||
document.getElementById('update-online-content').style.display = | |||
'block'; | |||
}) | |||
.catch(function (error) { | |||
document.getElementById('update-online-loading').innerHTML = | |||
'Unable to load the latest UPDate Online article.'; | |||
console.error(error); | |||
}); | |||
})(); | })(); | ||
</script> | </script> | ||
</includeonly> | </includeonly> | ||