';
}
});
}
/* =========================
CREATE BLOG CARD
========================= */
function createPostCard(post) {
let imageURL = "";
/*
* Get featured image from WordPress API
*/
if (
post._embedded &&
post._embedded["wp:featuredmedia"] &&
post._embedded["wp:featuredmedia"][0]
) {
imageURL =
post._embedded["wp:featuredmedia"][0].source_url;
}
/*
* Fallback image if a post doesn't
* have a featured image
*/
if (!imageURL) {
imageURL =
"https://images.unsplash.com/photo-1497366754035-f200968a6e72?auto=format&fit=crop&w=1200&q=80";
}
/*
* Format date
*/
const date = new Date(post.date);
const formattedDate =
date.toLocaleDateString("en-IN", {
day: "numeric",
month: "long",
year: "numeric"
});
/*
* Create card
*/
const card = document.createElement("article");
card.className = "itrain-card";
card.innerHTML = `
`;
grid.appendChild(card);
}
/* =========================
LOAD MORE BUTTON
========================= */
loadMoreButton.addEventListener("click", function() {
currentPage++;
loadPosts(currentPage);
});
/* =========================
INITIAL LOAD
========================= */
loadPosts(currentPage);
})();