Widget:UPMakingADifference: Difference between revisions
Appearance
Created page with " <includeonly> <div class="update-news"> <div class="update-online-loading"> Loading latest Making a Difference article... </div> <div class="update-online-content" style="display:none;"> <div class="update-news-image"> <img class="update-online-image" src="" alt="" style="display:none;"> </div> <div class="update-news-content"> <div class="update-..." |
No edit summary |
||
| Line 42: | Line 42: | ||
/* | /* | ||
* | * FIND THIS WIDGET INSTANCE | ||
*/ | */ | ||
| Line 54: | Line 54: | ||
return; | return; | ||
} | } | ||
/* | /* | ||
* | * FIND ELEMENTS INSIDE THIS WIDGET | ||
*/ | */ | ||
| Line 79: | Line 80: | ||
var dateElement = | var dateElement = | ||
widget.querySelector('.update-online-date'); | widget.querySelector('.update-online-date'); | ||
/* | /* | ||
* UP | * UP MAKING A DIFFERENCE API | ||
* Category ID: 5063 | |||
*/ | */ | ||
var api = | var api = | ||
'https://up.edu.ph/wp-json/wp/v2/posts' + | 'https://up.edu.ph/wp-json/wp/v2/posts' + | ||
'?categories=5063&per_page=1'; | '?categories=5063&per_page=1&_embed'; | ||
/* | /* | ||
* | * RETRIEVE THE LATEST ARTICLE | ||
*/ | */ | ||
| Line 113: | Line 117: | ||
var post = posts[0]; | var post = posts[0]; | ||
/* | /* | ||
| Line 118: | Line 123: | ||
*/ | */ | ||
title.innerHTML = post.title.rendered; | title.innerHTML = | ||
post.title.rendered; | |||
/* | /* | ||
| Line 124: | Line 131: | ||
*/ | */ | ||
excerpt.innerHTML = post.excerpt.rendered; | excerpt.innerHTML = | ||
post.excerpt.rendered; | |||
/* | /* | ||
| Line 130: | Line 139: | ||
*/ | */ | ||
link.href = post.link; | link.href = | ||
post.link; | |||
/* | /* | ||
| Line 136: | Line 147: | ||
*/ | */ | ||
var articleDate = new Date(post.date); | var articleDate = | ||
new Date(post.date); | |||
dateElement.textContent = | dateElement.textContent = | ||
| Line 148: | Line 160: | ||
); | ); | ||
/* | /* | ||
* | * GET FEATURED THUMBNAIL | ||
* | |||
* Prefer the medium-sized image. | |||
* Fall back to the thumbnail size, | |||
* then the original featured image. | |||
*/ | */ | ||
var | var imageUrl = ''; | ||
if ( | |||
post._embedded && | |||
post._embedded['wp:featuredmedia'] && | |||
post._embedded['wp:featuredmedia'].length > 0 | |||
) { | |||
var media = | |||
post._embedded['wp:featuredmedia'][0]; | |||
var sizes = | |||
media.media_details && | |||
media.media_details.sizes | |||
? media.media_details.sizes | |||
: {}; | |||
if ( | |||
sizes.medium && | |||
sizes.medium.source_url | |||
) { | |||
imageUrl = | |||
sizes.medium.source_url; | |||
} else if ( | |||
sizes.thumbnail && | |||
sizes.thumbnail.source_url | |||
) { | |||
imageUrl = | |||
sizes.thumbnail.source_url; | |||
} else if (media.source_url) { | |||
imageUrl = | |||
media.source_url; | |||
} | } | ||
} | } | ||
/* | /* | ||
* DISPLAY | * DISPLAY FEATURED THUMBNAIL | ||
*/ | */ | ||
if ( | if (imageUrl) { | ||
image.src = | |||
imageUrl; | |||
image.alt = | |||
post.title.rendered | |||
.replace(/<[^>]*>/g, ''); | |||
image.style.display = | |||
'block'; | |||
} | |||
/* | /* | ||
* SHOW | * SHOW ARTICLE CONTENT | ||
*/ | */ | ||
loading.style.display = 'none'; | loading.style.display = | ||
content.style.display = 'flex'; | 'none'; | ||
content.style.display = | |||
'flex'; | |||
}) | }) | ||
/* | |||
* ERROR HANDLING | |||
*/ | |||
.catch(function (error) { | .catch(function (error) { | ||
| Line 258: | Line 270: | ||
Displays the latest article from the UP website's | Displays the latest article from the UP website's | ||
Making a Difference category, including its publication | Making a Difference category, including its featured | ||
date, excerpt, article link | thumbnail, publication date, excerpt, and article link. | ||
=== Usage === | === Usage === | ||
Revision as of 23:53, 22 October 2026
UP Making a Difference Widget
Displays the latest article from the UP website's Making a Difference category, including its featured thumbnail, publication date, excerpt, and article link.
Usage
{{#widget:UPMakingADifference}}