Widget:UPDateOnline: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 9: | Line 9: | ||
<div id="update-online-content" style="display:none;"> | <div id="update-online-content" style="display:none;"> | ||
<!-- | <!-- News image --> | ||
<div class="update-news-image"> | <div class="update-news-image"> | ||
<img id="update-online-image" | <img id="update-online-image" | ||
| Line 50: | Line 50: | ||
/* | /* | ||
* Get the | * Get the latest UPDate Online article. | ||
* | |||
* We do NOT rely on the featured image. | |||
* Instead, we retrieve the article content | |||
* and find the first image inside it. | |||
*/ | */ | ||
var api = | var api = | ||
'https://upd.edu.ph/wp-json/wp/v2/posts' + | 'https://upd.edu.ph/wp-json/wp/v2/posts' + | ||
'?categories=4&per_page=1 | '?categories=4&per_page=1'; | ||
| Line 84: | Line 88: | ||
/* | /* | ||
* ----------------------------- | |||
* TITLE | * TITLE | ||
* ----------------------------- | |||
*/ | */ | ||
| Line 94: | Line 100: | ||
/* | /* | ||
* ----------------------------- | |||
* EXCERPT | * EXCERPT | ||
* ----------------------------- | |||
*/ | */ | ||
| Line 104: | Line 112: | ||
/* | /* | ||
* ----------------------------- | |||
* ARTICLE LINK | * ARTICLE LINK | ||
* ----------------------------- | |||
*/ | */ | ||
| Line 114: | Line 124: | ||
/* | /* | ||
* ----------------------------- | |||
* DATE | * DATE | ||
* ----------------------------- | |||
*/ | */ | ||
| Line 133: | Line 145: | ||
/* | /* | ||
* | * ----------------------------- | ||
* FIND FIRST ARTICLE IMAGE | |||
* ----------------------------- | |||
*/ | */ | ||
var temp = | |||
document.createElement('div'); | |||
temp.innerHTML = | |||
post.content.rendered; | |||
var firstImage = | |||
temp.querySelector('img'); | |||
image.alt = | if (firstImage) { | ||
var image = | |||
document.getElementById( | |||
'update-online-image' | |||
); | |||
/* | |||
* Get image URL | |||
*/ | |||
image.src = | |||
firstImage.src; | |||
/* | |||
* Use the article's | |||
* image alt text if available. | |||
*/ | |||
image.alt = | |||
firstImage.alt || | |||
post.title.rendered; | |||
} else { | } else { | ||
/* | /* | ||
* | * No image found. | ||
* Hide image container. | |||
* | |||
*/ | */ | ||
| Line 177: | Line 203: | ||
/* | /* | ||
* ----------------------------- | |||
* SHOW ARTICLE | * SHOW ARTICLE | ||
* ----------------------------- | |||
*/ | */ | ||
| Line 184: | Line 212: | ||
).style.display = | ).style.display = | ||
'none'; | 'none'; | ||
document.getElementById( | document.getElementById( | ||
| Line 194: | Line 223: | ||
/* | /* | ||
* ----------------------------- | |||
* ERROR HANDLING | * ERROR HANDLING | ||
* ----------------------------- | |||
*/ | */ | ||
| Line 217: | Line 248: | ||
== UPDate Online Widget == | == UPDate Online Widget == | ||
Displays the latest UPDate Online article | Displays the latest UPDate Online article and | ||
the first image appearing in the article. | |||
Usage | === Usage === | ||
<pre> | <pre> | ||
Revision as of 23:16, 6 October 2026
UPDate Online Widget
Displays the latest UPDate Online article and the first image appearing in the article.
Usage
{{#widget:UPDateOnline}}