diff --git a/src/StarterSite.php b/src/StarterSite.php index 4743a13..4d7206c 100644 --- a/src/StarterSite.php +++ b/src/StarterSite.php @@ -224,7 +224,7 @@ class StarterSite extends Site { private function recentPostsNews() { return Timber::get_posts([ 'post_type' => 'post', - 'posts_per_page' => 3, + 'posts_per_page' => -1, 'category_name' => 'noticias', 'post_status' => 'publish' ]); @@ -266,7 +266,7 @@ class StarterSite extends Site { return $logos; } - private function getVideosCarousel() { + private function getVideos() { return Timber::get_posts([ 'post_type' => 'videos', 'posts_per_page' => -1, // -1 = sin límite @@ -343,11 +343,62 @@ class StarterSite extends Site { // Hacer función disponible en Twig public function add_videos_embed_to_twig ($twig) { - error_log('Añadiendo función generar_embed a Twig'); // Debug + //error_log('Añadiendo función generar_embed a Twig'); // Debug $twig->addFunction(new \Twig\TwigFunction('generar_embed', [$this, 'generar_embed_universal'])); return $twig; } + private function getPaginasAcerca() { + return Timber::get_posts([ + 'post_type' => 'acerca', + 'post_status' => 'publish', + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'posts_per_page' => -1, + + ]); + } + + private function getDocumentos() { + + $posts = Timber::get_posts([ + 'post_type' => 'documento', + 'post_status' => 'publish', + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'posts_per_page' => -1, + ]); + + error_log('Número de posts encontrados: ' . count($posts)); + + $documentos = []; + + foreach ($posts as $post) { + $doc = [ + 'id' => $post->ID, + 'title' => $post->title, + 'link' => $post->link, + 'content' => $post->content, + 'excerpt' => $post->excerpt, + ]; + + $archivo = get_field('documento', $post->ID); + + if ($archivo && is_array($archivo)) { + $doc['documento_url'] = $archivo['url'] ?? ''; + $doc['documento_filename'] = $archivo['filename'] ?? ''; + $doc['documento_filesize'] = size_format($archivo['filesize'] ?? 0); + $doc['documento_extension'] = pathinfo($archivo['filename'] ?? '', PATHINFO_EXTENSION); + $doc['thumbnail'] = get_the_post_thumbnail_url($post->ID, 'medium'); + } + + $documentos[] = $doc; + } + + return $documentos; + } + + //Global variables public function add_global_context($context) { @@ -357,10 +408,12 @@ class StarterSite extends Site { $context['botones_imagen'] = $this->getBotonesImagen(); $context['redes_sociales'] = $this->getIconsRRSS(); $context['logos_header'] = $this->getLogosHeader(); - $context['videos_carousel'] = $this->getVideosCarousel(); + $context['videos'] = $this->getVideos(); $context['ultimo_articulo_opinion'] = $this->getUltimoArticuloOpinion(); $context['posts_campana'] = $this->getCampanaArticles(); - + $context['paginas_acerca'] = $this->getPaginasAcerca(); + $context['documentos'] = $this->getDocumentos(); + return $context; }