{"id":2552,"date":"2025-07-19T23:50:00","date_gmt":"2025-07-19T23:50:00","guid":{"rendered":"https:\/\/normaleskildsen.mx\/eduprimaria\/?page_id=2552"},"modified":"2026-05-03T14:10:29","modified_gmt":"2026-05-03T14:10:29","slug":"noticias","status":"publish","type":"page","link":"https:\/\/normaleskildsen.mx\/eduprimaria\/noticias\/","title":{"rendered":"Noticias"},"content":{"rendered":"\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<section class=\"blog-section\">\n  <h2 class=\"section-title\">Nuestras actividades<\/h2>\n  <p class=\"section-desc\">\n    Esta secci\u00f3n est\u00e1 dedicada exclusivamente a las actividades de nuestra instituci\u00f3n.\n  <\/p>\n\n  <div class=\"month-filter\" id=\"month-buttons\"><\/div>\n  <div id=\"news-container\" class=\"news-grid\">\n    <p>Cargando publicaciones&#8230;<\/p>\n  <\/div>\n<\/section>\n\n<style>\n  .blog-section {\n    max-width: 1200px;\n    margin: 0 auto;\n    padding: 2rem;\n    font-family: 'Inter', sans-serif;\n    color: #1f2937;\n  }\n\n  .section-title {\n    text-align: center;\n    font-size: 1.8rem;\n    font-weight: 700;\n  }\n\n  .section-desc {\n    text-align: center;\n    color: #555;\n    max-width: 800px;\n    margin: 0.5rem auto 2rem;\n  }\n\n  .month-filter {\n    text-align: center;\n    margin-bottom: 2rem;\n  }\n\n  .month-btn {\n    background: none;\n    border: 2px solid #ff7b00;\n    color: #ff7b00;\n    border-radius: 20px;\n    padding: 0.5rem 1rem;\n    margin: 0.3rem;\n    cursor: pointer;\n    font-weight: 600;\n    transition: all 0.3s ease;\n  }\n\n  .month-btn.active,\n  .month-btn:hover {\n    background: #ff7b00;\n    color: white;\n  }\n\n  .news-grid {\n    display: grid;\n    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));\n    gap: 1.5rem;\n  }\n\n  .news-card {\n    background: white;\n    border-radius: 16px;\n    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);\n    overflow: hidden;\n    display: flex;\n    flex-direction: column;\n    transition: transform 0.3s ease;\n  }\n\n  .news-card:hover {\n    transform: translateY(-5px);\n  }\n\n  .news-card img {\n    width: 100%;\n    height: 220px;\n    object-fit: cover;\n    display: block;\n  }\n\n  .news-content {\n    padding: 1rem 1.2rem 1.5rem;\n  }\n\n  .news-content h3 {\n    font-size: 1.1rem;\n    margin-bottom: 0.5rem;\n    color: #111827;\n  }\n\n  .date {\n    color: #6b7280;\n    font-size: 0.9rem;\n    margin-bottom: 0.8rem;\n  }\n\n  .btn-read {\n    display: inline-block;\n    background-color: #ff7b00;\n    color: white;\n    text-decoration: none;\n    padding: 0.6rem 1.2rem;\n    border-radius: 8px;\n    margin-top: 0.8rem;\n    font-weight: 600;\n    transition: background 0.3s ease;\n  }\n\n  .btn-read:hover {\n    background-color: #e76f00;\n  }\n<\/style>\n\n<script>\n(async function () {\n  const monthButtons = document.getElementById(\"month-buttons\");\n  const newsContainer = document.getElementById(\"news-container\");\n  const fallbackImage = \"https:\/\/via.placeholder.com\/600x400?text=Sin+imagen\";\n  const currentYear = new Date().getFullYear();\n\n  function limpiarHTML(html) {\n    const temp = document.createElement(\"div\");\n    temp.innerHTML = html || \"\";\n    return temp.textContent.trim();\n  }\n\n  function recortarTexto(texto, limite) {\n    if (texto.length <= limite) return texto;\n    return texto.substring(0, limite).trim() + \"\u2026\";\n  }\n\n  function renderPosts(list) {\n    if (!list || !list.length) {\n      newsContainer.innerHTML = `<p>No hay publicaciones disponibles para este mes en ${currentYear}.<\/p>`;\n      return;\n    }\n\n    newsContainer.innerHTML = \"\";\n\n    list.forEach((post) => {\n      const title = limpiarHTML(post.title?.rendered || \"Sin t\u00edtulo\");\n      const link = post.link || \"#\";\n      const date = new Date(post.date).toLocaleDateString(\"es-MX\", {\n        day: \"numeric\",\n        month: \"long\",\n        year: \"numeric\"\n      });\n      const excerptRaw = limpiarHTML(post.excerpt?.rendered || \"\");\n      const excerpt = recortarTexto(\n        excerptRaw || \"Consulta esta publicaci\u00f3n para conocer m\u00e1s detalles.\",\n        160\n      );\n      const img = post._embedded?.[\"wp:featuredmedia\"]?.[0]?.source_url || fallbackImage;\n\n      const card = document.createElement(\"div\");\n      card.className = \"news-card\";\n      card.innerHTML = `\n        <img decoding=\"async\" src=\"${img}\" alt=\"${title}\" loading=\"lazy\">\n        <div class=\"news-content\">\n          <h3>${title}<\/h3>\n          <p class=\"date\">${date}<\/p>\n          <p>${excerpt}<\/p>\n          <a href=\"${link}\" class=\"btn-read\" target=\"_blank\" rel=\"noopener noreferrer\">Leer m\u00e1s<\/a>\n        <\/div>\n      `;\n      newsContainer.appendChild(card);\n    });\n  }\n\n  async function fetchAllPosts() {\n    const baseUrl = \"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/posts\";\n    const params = new URLSearchParams({\n      _embed: \"1\",\n      per_page: \"100\",\n      orderby: \"date\",\n      order: \"desc\",\n      status: \"publish\",\n      _: Date.now().toString()\n    });\n\n    const firstResponse = await fetch(`${baseUrl}?${params.toString()}&page=1`, {\n      method: \"GET\",\n      cache: \"no-store\"\n    });\n\n    if (!firstResponse.ok) {\n      throw new Error(\"No se pudieron obtener las publicaciones\");\n    }\n\n    const totalPages = Number(firstResponse.headers.get(\"X-WP-TotalPages\") || \"1\");\n    const firstPagePosts = await firstResponse.json();\n    let allPosts = [...firstPagePosts];\n\n    for (let page = 2; page <= totalPages; page++) {\n      const response = await fetch(`${baseUrl}?${params.toString()}&#038;page=${page}`, {\n        method: \"GET\",\n        cache: \"no-store\"\n      });\n\n      if (!response.ok) continue;\n\n      const pagePosts = await response.json();\n      allPosts = allPosts.concat(pagePosts);\n    }\n\n    return allPosts;\n  }\n\n  try {\n    const posts = await fetchAllPosts();\n\n    const currentYearPosts = posts.filter((post) => {\n      return new Date(post.date).getFullYear() === currentYear;\n    });\n\n    if (!currentYearPosts.length) {\n      monthButtons.innerHTML = \"\";\n      newsContainer.innerHTML = `<p>No hay publicaciones disponibles para ${currentYear}.<\/p>`;\n      return;\n    }\n\n    const grouped = {};\n\n    currentYearPosts.forEach((post) => {\n      const date = new Date(post.date);\n      const monthNumber = String(date.getMonth() + 1).padStart(2, \"0\");\n      const monthName = date.toLocaleString(\"es-MX\", { month: \"long\" });\n      const key = `${currentYear}-${monthNumber}`;\n      const label = `${monthName.charAt(0).toUpperCase() + monthName.slice(1)} ${currentYear}`;\n\n      if (!grouped[key]) {\n        grouped[key] = {\n          label,\n          posts: []\n        };\n      }\n\n      grouped[key].posts.push(post);\n    });\n\n    const months = Object.keys(grouped).sort((a, b) => b.localeCompare(a));\n\n    monthButtons.innerHTML = \"\";\n\n    months.forEach((monthKey, index) => {\n      const btn = document.createElement(\"button\");\n      btn.textContent = grouped[monthKey].label;\n      btn.className = \"month-btn\" + (index === 0 ? \" active\" : \"\");\n\n      btn.addEventListener(\"click\", () => {\n        document.querySelectorAll(\".month-btn\").forEach((b) => b.classList.remove(\"active\"));\n        btn.classList.add(\"active\");\n        renderPosts(grouped[monthKey].posts);\n      });\n\n      monthButtons.appendChild(btn);\n    });\n\n    renderPosts(grouped[months[0]].posts);\n  } catch (error) {\n    console.error(\"Error al cargar publicaciones:\", error);\n    monthButtons.innerHTML = \"\";\n    newsContainer.innerHTML = \"<p>No se pudieron cargar las publicaciones por el momento.<\/p>\";\n  }\n})();\n<\/script>\n\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:10%\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:80%\"><\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:10%\"><\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nuestras actividades Esta secci\u00f3n est\u00e1 dedicada exclusivamente a las actividades de nuestra instituci\u00f3n. Cargando publicaciones&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","h5ap_radio_sources":[],"footnotes":""},"class_list":["post-2552","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/pages\/2552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/comments?post=2552"}],"version-history":[{"count":8,"href":"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/pages\/2552\/revisions"}],"predecessor-version":[{"id":4681,"href":"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/pages\/2552\/revisions\/4681"}],"wp:attachment":[{"href":"https:\/\/normaleskildsen.mx\/eduprimaria\/wp-json\/wp\/v2\/media?parent=2552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}