ADD archive-videos
This commit is contained in:
@ -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)
|
||||
==========================
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Category 'noticias'
|
||||
* Temporal. De momento no pasan por aquí.
|
||||
*/
|
||||
global $params;
|
||||
$context = Timber::context();
|
||||
|
||||
// var_dump(get_cat_ID('Noticias'));
|
||||
$category = get_category_by_slug('noticias');
|
||||
$query = array(
|
||||
|
||||
@ -5,9 +5,7 @@
|
||||
|
||||
$context = Timber::context();
|
||||
|
||||
// WordPress ya tiene la paginación correcta en la query
|
||||
$context['posts_opinion'] = Timber::get_posts();
|
||||
|
||||
$context['posts_opinion'] = Timber::get_posts(); // WordPress ya tiene la paginación correcta en la query
|
||||
error_log('✅ archive-opinion - Posts: ' . count($context['posts_opinion']));
|
||||
|
||||
Timber::render('templates/page-opinion.twig', $context);
|
||||
|
||||
@ -5,8 +5,19 @@
|
||||
|
||||
$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
|
||||
$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);
|
||||
|
||||
21
archive.md
Normal file
21
archive.md
Normal 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
|
||||
]);
|
||||
==========================
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -309,6 +285,17 @@ class StarterSite extends Site {
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
];
|
||||
|
||||
@ -85,8 +85,8 @@
|
||||
</div> #}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
{% else %}
|
||||
No hay vídeos
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{% extends 'layouts/base.twig' %}
|
||||
|
||||
{% 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) }}#}
|
||||
|
||||
<section class="archive-videos my-3">
|
||||
|
||||
Reference in New Issue
Block a user