From 9abdf1249d75bb6796446522790152efddc763dc Mon Sep 17 00:00:00 2001 From: gustavo Date: Thu, 16 Oct 2025 11:26:27 +0000 Subject: [PATCH] ADD archive-videos --- NewArchive.md | 9 --- archive-noticias.php | 2 +- archive-opinion.php | 4 +- archive-videos.php | 13 +++- archive.md | 21 ++++++ src/StarterSite.php | 75 ++++++---------------- views/partials/section-videos&opinion.twig | 4 +- views/templates/page-videos.twig | 2 +- 8 files changed, 56 insertions(+), 74 deletions(-) delete mode 100644 NewArchive.md create mode 100644 archive.md diff --git a/NewArchive.md b/NewArchive.md deleted file mode 100644 index 6433ade..0000000 --- a/NewArchive.md +++ /dev/null @@ -1,9 +0,0 @@ - -En Traducciones > ajustes > post type: marcar el post type. -========================== -En ACF marcar archive y jerárquico. -En URLs añadir el nombre del slug (Ej: videos) -========================== -Crear archive-slug.php (Ej: archive-videos.php) -========================== - diff --git a/archive-noticias.php b/archive-noticias.php index 2eca600..36e9256 100644 --- a/archive-noticias.php +++ b/archive-noticias.php @@ -1,10 +1,10 @@ found_posts); + // WordPress ya tiene la paginación correcta en la query -$context['videos'] = Timber::get_posts(); +$context['videos'] = Timber::get_posts([ + 'post_type' => 'videos', + 'posts_per_page' => -1, + 'lang' => '' // Importante: vacío para obtener todos +]); + error_log('✅ archive-videos - Posts: ' . count($context['videos'])); Timber::render('templates/page-videos.twig', $context); diff --git a/archive.md b/archive.md new file mode 100644 index 0000000..d9ef365 --- /dev/null +++ b/archive.md @@ -0,0 +1,21 @@ + +Idiomas +> Ajustes > post type: marcar el post type. +> Traducciones. Filtrar por "Slugs de las URLs". Traducir las palabras clave +========================== +ACF +> Tipos de contenido. Elegir el que quieres configurar. +> Marcar archive y jerárquico. +> URLs añadir el nombre del slug (Ej: videos) +========================== +Crear archive-slug.php (Ej: archive-videos.php) + +Si se quieren recibir todos los posts, independientemente del idioma. Ejemplo: + +$context['videos'] = Timber::get_posts([ + 'post_type' => 'videos', + 'posts_per_page' => -1, + 'lang' => '' // Importante: vacío para obtener todos +]); +========================== + diff --git a/src/StarterSite.php b/src/StarterSite.php index 5cea73b..4cf9d80 100644 --- a/src/StarterSite.php +++ b/src/StarterSite.php @@ -57,10 +57,9 @@ class StarterSite extends Site { return $classes; }, 10, 3); - // Añadir estilo en el admin + // Añadir estilo en el admin a los "ids_especiales" add_action('admin_head', function() use ($ids_especiales) { if (empty($ids_especiales)) return; - $css = ''; foreach ($ids_especiales as $id) { $css .= "tr#post-$id td { background-color: #fffae6 !important; border-top: 2px solid #f0c000 !important; }"; @@ -86,29 +85,6 @@ class StarterSite extends Site { }, 10, 2); /** FIN *************POST "QUÉ ES LA CNT" */ - // ***************TEMP: Debug archivo vídeos - // add_action('template_redirect', function() { - // global $wp_query; - // error_log('🔍 Template: ' . get_query_var('post_type')); - // error_log('🔍 Is post type archive: ' . (is_post_type_archive() ? 'YES' : 'NO')); - // error_log('🔍 Post type archive: ' . (is_post_type_archive('videos') ? 'VIDEOS' : 'NO')); - - // }); - - // add_action('init', function() { - // add_rewrite_rule( - // '(eu|es)/videos/?$', - // 'index.php?lang=$matches[1]&post_type=videos', - // 'top' - // ); - // add_rewrite_rule( - // '(eu|es)/videos/page/([0-9]{1,})/?$', - // 'index.php?lang=$matches[1]&post_type=videos&paged=$matches[2]', - // 'top' - // ); - // }); - // ****************************************** - parent::__construct(); } @@ -308,6 +284,17 @@ class StarterSite extends Site { $polylang_data['home_urls'][$lang['slug']] = $lang['url']; } } + + // Si no hay videos en euskera, el botón euskera no detecta videos en ese idioma y te lleva a la home. + if (is_post_type_archive('videos')) { + foreach ($polylang_data['languages'] as $slug => &$lang) { + if ($slug === 'es') { + $lang['url'] = home_url('/es/videos/'); + } elseif ($slug === 'eu') { + $lang['url'] = home_url('/eu/bideoak/'); + } + } + } return $polylang_data; } @@ -384,37 +371,6 @@ class StarterSite extends Site { return $logos; } - private function getVideos() { - - $post = Timber::get_post(); - //error_log('✅ ID Página: ' . $post->ID); - - $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; - - if ($post && ( $post->ID === 9 || $post->ID === 392) ) { - global $wp_query; - $temp_query = $wp_query; - - $wp_query = new \WP_Query([ - 'post_type' => 'videos', - 'posts_per_page' => 20, - 'post_status' => 'publish', - 'orderby' => 'date', - 'order' => 'DESC', - 'paged' => $paged, - ]); - - // Timber::get_posts() SIN PARÁMETROS usa la query global ($wp_query) - $posts = Timber::get_posts(); // Lee de la query global que acabamos de crear - $pagination = new \Timber\Pagination($wp_query->max_num_pages); - $wp_query = $temp_query; // Restaurar query original - - return $posts; - } - - return ['posts' => [], 'pagination' => null]; - } - private function getPaginasAcerca() { return Timber::get_posts([ 'post_type' => 'acerca', @@ -794,13 +750,18 @@ class StarterSite extends Site { } public function getVideosSlider() { + + $post = Timber::get_post(); + error_log('✅ getVideosSlider - ID Página: ' . $post->ID); + return [ 'posts' => Timber::get_posts([ 'post_type' => 'videos', 'posts_per_page' => -1, 'post_status' => 'publish', 'orderby' => 'date', - 'order' => 'DESC' + 'order' => 'DESC', + 'lang' => '' // Importante: vacío para obtener todos ]), 'pagination' => null ]; diff --git a/views/partials/section-videos&opinion.twig b/views/partials/section-videos&opinion.twig index d238aca..0d0584c 100644 --- a/views/partials/section-videos&opinion.twig +++ b/views/partials/section-videos&opinion.twig @@ -85,8 +85,8 @@ #} {% endif %} - - + {% else %} + No hay vídeos {% endif %} diff --git a/views/templates/page-videos.twig b/views/templates/page-videos.twig index 3776562..79f77dd 100644 --- a/views/templates/page-videos.twig +++ b/views/templates/page-videos.twig @@ -1,7 +1,7 @@ {% extends 'layouts/base.twig' %} {% block content %} -

{{ __('Vídeos', 'Sindikatua') }}

+

{{ __('Vídeos', 'Sindikatua') }}

{# {{ dump(videos.pagination) }}#}