ADD archive-videos

This commit is contained in:
2025-10-16 11:26:27 +00:00
parent 2f6b47a576
commit 9abdf1249d
8 changed files with 56 additions and 74 deletions

View File

@ -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)
==========================

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* Category 'noticias' * Category 'noticias'
* Temporal. De momento no pasan por aquí.
*/ */
global $params; global $params;
$context = Timber::context(); $context = Timber::context();
// var_dump(get_cat_ID('Noticias')); // var_dump(get_cat_ID('Noticias'));
$category = get_category_by_slug('noticias'); $category = get_category_by_slug('noticias');
$query = array( $query = array(

View File

@ -5,9 +5,7 @@
$context = Timber::context(); $context = Timber::context();
// WordPress ya tiene la paginación correcta en la query $context['posts_opinion'] = Timber::get_posts(); // WordPress ya tiene la paginación correcta en la query
$context['posts_opinion'] = Timber::get_posts();
error_log('✅ archive-opinion - Posts: ' . count($context['posts_opinion'])); error_log('✅ archive-opinion - Posts: ' . count($context['posts_opinion']));
Timber::render('templates/page-opinion.twig', $context); Timber::render('templates/page-opinion.twig', $context);

View File

@ -5,8 +5,19 @@
$context = Timber::context(); $context = Timber::context();
// Debug
global $wp_query;
error_log('🔍 Language: ' . (function_exists('pll_current_language') ? pll_current_language() : 'no polylang'));
error_log('🔍 Post type: ' . get_query_var('post_type'));
error_log('🔍 Posts found by WP: ' . $wp_query->found_posts);
// WordPress ya tiene la paginación correcta en la query // 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'])); error_log('✅ archive-videos - Posts: ' . count($context['videos']));
Timber::render('templates/page-videos.twig', $context); Timber::render('templates/page-videos.twig', $context);

21
archive.md Normal file
View File

@ -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
]);
==========================

View File

@ -57,10 +57,9 @@ class StarterSite extends Site {
return $classes; return $classes;
}, 10, 3); }, 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) { add_action('admin_head', function() use ($ids_especiales) {
if (empty($ids_especiales)) return; if (empty($ids_especiales)) return;
$css = ''; $css = '';
foreach ($ids_especiales as $id) { foreach ($ids_especiales as $id) {
$css .= "tr#post-$id td { background-color: #fffae6 !important; border-top: 2px solid #f0c000 !important; }"; $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); }, 10, 2);
/** FIN *************POST "QUÉ ES LA CNT" */ /** 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(); parent::__construct();
} }
@ -308,6 +284,17 @@ class StarterSite extends Site {
$polylang_data['home_urls'][$lang['slug']] = $lang['url']; $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; return $polylang_data;
} }
@ -384,37 +371,6 @@ class StarterSite extends Site {
return $logos; 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() { private function getPaginasAcerca() {
return Timber::get_posts([ return Timber::get_posts([
'post_type' => 'acerca', 'post_type' => 'acerca',
@ -794,13 +750,18 @@ class StarterSite extends Site {
} }
public function getVideosSlider() { public function getVideosSlider() {
$post = Timber::get_post();
error_log('✅ getVideosSlider - ID Página: ' . $post->ID);
return [ return [
'posts' => Timber::get_posts([ 'posts' => Timber::get_posts([
'post_type' => 'videos', 'post_type' => 'videos',
'posts_per_page' => -1, 'posts_per_page' => -1,
'post_status' => 'publish', 'post_status' => 'publish',
'orderby' => 'date', 'orderby' => 'date',
'order' => 'DESC' 'order' => 'DESC',
'lang' => '' // Importante: vacío para obtener todos
]), ]),
'pagination' => null 'pagination' => null
]; ];

View File

@ -85,8 +85,8 @@
</div> #} </div> #}
{% endif %} {% endif %}
</div> </div>
{% else %}
No hay vídeos
{% endif %} {% endif %}
</div> </div>

View File

@ -1,7 +1,7 @@
{% extends 'layouts/base.twig' %} {% extends 'layouts/base.twig' %}
{% block content %} {% block content %}
<h1 class="my-5 position-relative fs-4 fw-bold sp-module-title">{{ __('Vídeos', 'Sindikatua') }}</h1> <h1 class="my-5 position-relative fs-3 fw-bold sp-module-title">{{ __('Vídeos', 'Sindikatua') }}</h1>
{# {{ dump(videos.pagination) }}#} {# {{ dump(videos.pagination) }}#}
<section class="archive-videos my-3"> <section class="archive-videos my-3">