| Server IP : 127.0.0.1 / Your IP : 216.73.216.109 Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10 System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64 User : SERVERWEB ( 0) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/laragon/www/assets/js/ |
Upload File : |
async function getNews() {
const apiUrl = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/posts";
try {
const noticias = await decode_api(apiUrl);
const urlUser = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/users";
const userList = await decode_api(urlUser);
const urlCategories = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/categories";
const catList = await decode_api(urlCategories);
const urlTags = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/tags";
const tagList = await decode_api(urlTags);
const currentPage = 1;
const perPage = 5;
const startIdx = (currentPage - 1) * perPage;
const endIdx = startIdx + perPage;
const items = noticias.slice(startIdx, endIdx);
} catch (error) {
console.error("Error:", error);
}
}
// custom.js
async function decode_api(apiUrl) {
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error("Failed to fetch data from API");
}
const data = await response.json();
return data;
} catch (error) {
console.error("API Error:", error);
throw error; // Re-throw the error so it can be caught in the HTML script
}
}
// Get the news data and update the placeholders in the HTML
const apiUrl = "https://prensa.quillacollo.gob.bo/wp-json/wp/v2/posts";
decode_api(apiUrl)
.then((noticias) => {
// Assuming noticias is an array of news items fetched from the API
noticias.forEach((post, index) => {
const listItem = document.querySelectorAll(".offer_li")[index];
const imageWrapper = listItem.querySelector(".image_wrapper img");
const titleLink = listItem.querySelector(".post-corporate-title a");
const badgeLink = listItem.querySelector(".badge");
const description = listItem.querySelector(".big");
const readMoreLink = listItem.querySelector(".post-corporate-link a");
// Update the placeholders with data from noticias
imageWrapper.src = post.image_url; // Replace post.image_url with the correct image URL property
titleLink.href = post.link; // Replace post.link with the correct link property
titleLink.textContent = post.title.rendered;
badgeLink.href = post.link;
description.textContent = post.excerpt.rendered;
readMoreLink.href = post.link;
});
})
.catch((error) => {
console.error("Error fetching data:", error);
});
getNews();