FIX pagination
This commit is contained in:
4
page.php
4
page.php
@ -26,7 +26,7 @@ $cast_subpagina_servicios = ($parent && ($parent->post_name === 'servicios-priva
|
||||
$eusk_subpagina_zerbitzu = ($parent && ($parent->post_name === 'zerbitzu-pribatuak' || $parent->post_name === 'zerbitzu-publikoak'));
|
||||
$subpagina_industria = ($parent && ($parent->post_name === 'industria'));
|
||||
// Verificar si es una página padre de servicios
|
||||
$slug_actual = $post->post_name;
|
||||
$slug_actual = $timber_post->post_name;
|
||||
//error_log('✅ (page.php) Slug actual: ' . $slug_actual);
|
||||
$pagina_servicios = ($slug_actual === 'servicios-privados' || $slug_actual === 'servicios-publicos' || $slug_actual === 'zerbitzu-pribatuak' || $slug_actual === 'zerbitzu-publikoak');
|
||||
|
||||
@ -44,6 +44,6 @@ if ($parent && ($parent->post_name === 'contactos' || $parent->post_name === 'ko
|
||||
//error_log('✅ (page.php) Página "Industria": ' . $parent->post_name);
|
||||
Timber::render('templates/single-industria.twig', $context);
|
||||
} else {
|
||||
//error_log('✅ (page.php) Página: ' . $parent->post_name);
|
||||
error_log('✅ (page.php) Página: ' . $parent->post_name);
|
||||
Timber::render(array('templates/page-' . $timber_post->post_name . '.twig'), $context);
|
||||
}
|
||||
@ -44,39 +44,81 @@ class StarterSite extends Site {
|
||||
}
|
||||
});
|
||||
|
||||
// Arreglar paginación para post type "opinion"
|
||||
// add_action('init', function() {
|
||||
// // Asegurarse de que opinion tenga archive habilitado
|
||||
// global $wp_post_types;
|
||||
// if (isset($wp_post_types['opinion'])) {
|
||||
// $wp_post_types['opinion']->has_archive = true;
|
||||
// }
|
||||
// });
|
||||
//Arreglar paginación para post type "opinion"
|
||||
add_action('init', function() {
|
||||
// Asegurarse de que opinion tenga archive habilitado
|
||||
global $wp_post_types;
|
||||
if (isset($wp_post_types['opinion'])) {
|
||||
$wp_post_types['opinion']->has_archive = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Añadir regla de rewrite personalizada para paginación de "opinion"
|
||||
// add_action('init', function() {
|
||||
// add_rewrite_rule(
|
||||
// '^opinion/page/([0-9]{1,})/?$',
|
||||
// 'index.php?post_type=opinion&paged=$matches[1]',
|
||||
// 'top'
|
||||
// );
|
||||
//Añadir regla de rewrite personalizada para paginación de "opinion"
|
||||
add_action('init', function() {
|
||||
add_rewrite_rule(
|
||||
'^opinion/page/([0-9]{1,})/?$',
|
||||
'index.php?post_type=opinion&paged=$matches[1]',
|
||||
'top'
|
||||
);
|
||||
|
||||
// // Si usas multiidioma, añade también para cada idioma
|
||||
// add_rewrite_rule(
|
||||
// '^([a-z]{2})/opinion/page/([0-9]{1,})/?$',
|
||||
// 'index.php?lang=$matches[1]&post_type=opinion&paged=$matches[2]',
|
||||
// 'top'
|
||||
// );
|
||||
// }, 10);
|
||||
// Si usas multiidioma, añade también para cada idioma
|
||||
add_rewrite_rule(
|
||||
'^([a-z]{2})/opinion/page/([0-9]{1,})/?$',
|
||||
'index.php?lang=$matches[1]&post_type=opinion&paged=$matches[2]',
|
||||
'top'
|
||||
);
|
||||
}, 10);
|
||||
|
||||
// Forzar flush de rewrite rules (solo una vez)
|
||||
// add_action('init', function() {
|
||||
// if (get_option('opinion_pagination_flushed') !== 'yes') {
|
||||
// flush_rewrite_rules();
|
||||
// update_option('opinion_pagination_flushed', 'yes');
|
||||
// }
|
||||
// }, 999);
|
||||
//Forzar flush de rewrite rules (solo una vez)
|
||||
add_action('init', function() {
|
||||
if (get_option('opinion_pagination_flushed') !== 'yes') {
|
||||
flush_rewrite_rules();
|
||||
update_option('opinion_pagination_flushed', 'yes');
|
||||
}
|
||||
}, 999);
|
||||
|
||||
/** POST "QUÉ ES LA CNT" */
|
||||
// Previene borrar el post "Qué es la cnt" porque forma parte del menú //
|
||||
$ids_especiales = [10982, 4791, 10981];
|
||||
define('POST_ESPECIAL_TYPE', 'acerca');
|
||||
|
||||
// Añadir clase personalizada al tr del listado de posts
|
||||
add_filter('post_class', function($classes, $class, $post_id) use ($ids_especiales) {
|
||||
if (in_array($post_id, $ids_especiales)) {
|
||||
$classes[] = 'post-especial';
|
||||
}
|
||||
return $classes;
|
||||
}, 10, 3);
|
||||
|
||||
// Añadir estilo en el admin
|
||||
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; }";
|
||||
}
|
||||
|
||||
echo "<style>$css</style>";
|
||||
});
|
||||
|
||||
// Ocultar el enlace "Mover a la papelera" en el listado
|
||||
add_filter('post_row_actions', function($actions, $post) use ($ids_especiales) {
|
||||
if ($post->post_type === POST_ESPECIAL_TYPE && in_array($post->ID, $ids_especiales)) {
|
||||
unset($actions['trash']);
|
||||
}
|
||||
return $actions;
|
||||
}, 10, 2);
|
||||
|
||||
// Mensaje de advertencia en los posts
|
||||
add_filter('display_post_states', function($post_states, $post) use ($ids_especiales) {
|
||||
if ($post->post_type === 'acerca' && in_array($post->ID, $ids_especiales)) {
|
||||
$post_states['protegido'] = '🔒 No se puede borrar';
|
||||
}
|
||||
return $post_states;
|
||||
}, 10, 2);
|
||||
|
||||
/** FIN *************POST "QUÉ ES LA CNT" */
|
||||
|
||||
|
||||
parent::__construct();
|
||||
@ -280,8 +322,7 @@ class StarterSite extends Site {
|
||||
private function getPostsNews() {
|
||||
|
||||
$post = Timber::get_post();
|
||||
// if ($post) { error_log('✅ Este es el ID Página news: ' . $post->ID);}
|
||||
|
||||
//if ($post) { error_log('✅ Este es el ID Página news: ' . $post->ID);}
|
||||
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
|
||||
|
||||
//84=portada CAST & 331= portada EUSKARA
|
||||
@ -302,7 +343,7 @@ class StarterSite extends Site {
|
||||
|
||||
$wp_query = new \WP_Query([
|
||||
'post_type' => 'post',
|
||||
'category_name' => 'noticias',
|
||||
'category_name' => 'noticias',
|
||||
'posts_per_page' => 10,
|
||||
'post_status' => 'publish',
|
||||
'orderby' => 'date',
|
||||
@ -310,20 +351,19 @@ class StarterSite extends Site {
|
||||
'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' => $posts,
|
||||
'pagination' => $pagination
|
||||
];
|
||||
$pagination = new \Timber\Pagination();
|
||||
$wp_query = $temp_query; // Restaurar query original
|
||||
|
||||
return $posts;
|
||||
|
||||
}
|
||||
|
||||
return ['posts' => [], 'pagination' => null];
|
||||
|
||||
//error_log('❌ getPostsNews - No coincide con ninguna página');
|
||||
return [
|
||||
'posts' => [],
|
||||
'pagination' => null
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@ -387,7 +427,7 @@ class StarterSite extends Site {
|
||||
|
||||
$wp_query = new \WP_Query([
|
||||
'post_type' => 'videos',
|
||||
'posts_per_page' => 12,
|
||||
'posts_per_page' => 20,
|
||||
'post_status' => 'publish',
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
@ -396,15 +436,10 @@ class StarterSite extends Site {
|
||||
|
||||
// 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' => $posts,
|
||||
'pagination' => $pagination
|
||||
];
|
||||
return $posts;
|
||||
}
|
||||
|
||||
return ['posts' => [], 'pagination' => null];
|
||||
@ -446,7 +481,6 @@ class StarterSite extends Site {
|
||||
$wp_query = $temp_query; // Restaurar query original
|
||||
|
||||
return $posts;
|
||||
|
||||
}
|
||||
|
||||
return ['posts' => [], 'pagination' => null];
|
||||
@ -646,9 +680,9 @@ class StarterSite extends Site {
|
||||
return $grupos;
|
||||
}
|
||||
|
||||
/** Servicios públicos y privados */
|
||||
private function getSubpaginasServicios() {
|
||||
|
||||
// Detectar automáticamente si es servicios públicos o privados
|
||||
$current_post = get_post();
|
||||
$slug_actual = $current_post->post_name;
|
||||
|
||||
@ -668,7 +702,7 @@ class StarterSite extends Site {
|
||||
} else {
|
||||
return [
|
||||
'subpaginas' => [],
|
||||
'pagination' => null
|
||||
'pagination_Servicios' => null
|
||||
];
|
||||
}
|
||||
|
||||
@ -677,20 +711,17 @@ class StarterSite extends Site {
|
||||
error_log("🔴 Página '$path' no encontrada.");
|
||||
return [
|
||||
'subpaginas' => [],
|
||||
'pagination' => null
|
||||
'pagination_Servicios' => null
|
||||
];
|
||||
}
|
||||
|
||||
// Obtener el número de página actual
|
||||
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
|
||||
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // Obtener el número de página actual
|
||||
$posts_per_page = 6;
|
||||
|
||||
// Guardar la query global actual
|
||||
global $wp_query;
|
||||
global $wp_query; // Guardar la query global actual
|
||||
$temp_query = $wp_query;
|
||||
|
||||
// Crear nueva WP_Query
|
||||
$wp_query = new \WP_Query([
|
||||
$wp_query = new \WP_Query([ // Crear nueva WP_Query
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_parent' => $pag_servicios->ID,
|
||||
@ -700,24 +731,17 @@ class StarterSite extends Site {
|
||||
'paged' => $paged,
|
||||
]);
|
||||
|
||||
// Timber::get_posts() SIN PARÁMETROS usa la query global ($wp_query)
|
||||
$subpaginas = Timber::get_posts();
|
||||
|
||||
$subpaginas = Timber::get_posts(); // Timber::get_posts() SIN PARÁMETROS usa la query global ($wp_query)
|
||||
foreach ($subpaginas as $pagina) {
|
||||
$pagina->thumbnail = get_the_post_thumbnail_url($pagina->ID);
|
||||
$pagina->tipo_servicio = $tipo;
|
||||
}
|
||||
|
||||
// Crear objeto de paginación
|
||||
$pagination = new \Timber\Pagination($wp_query->max_num_pages);
|
||||
|
||||
// Restaurar query original
|
||||
$wp_query = $temp_query;
|
||||
$pagination = new \Timber\Pagination($wp_query->max_num_pages); // Crear objeto de paginación
|
||||
$wp_query = $temp_query; // Restaurar query original
|
||||
|
||||
return $subpaginas;
|
||||
|
||||
return [
|
||||
'subpaginas' => $subpaginas,
|
||||
'pagination' => $pagination
|
||||
];
|
||||
}
|
||||
|
||||
//Campos de contactos
|
||||
@ -838,24 +862,14 @@ class StarterSite extends Site {
|
||||
$context['posts_conflicts'] = $this->getConflictsCategory();
|
||||
$context['documentos'] = $this->getDocumentos();
|
||||
$context['enlaces'] = $this->getEnlaces();
|
||||
//$context['subpaginas_servicios'] = $this->getSubpaginasServicios();
|
||||
$context['contacto_info'] = $this->getContactoFields();
|
||||
$context['posts_industry'] = $this->getPostIndustry();
|
||||
$context['posts_noticias'] = $this->getPostsNews();
|
||||
$context['subpaginas_servicios'] = $this->getSubpaginasServicios();
|
||||
$context['videos'] = $this->getVideos();
|
||||
|
||||
$context = array_merge($context, $this->getPolylangData());
|
||||
|
||||
$videos_data = $this->getVideos();
|
||||
$context['videos'] = $videos_data['posts'];
|
||||
$context['pagination'] = $videos_data['pagination'];
|
||||
|
||||
$post_noticias_data = $this->getPostsNews();
|
||||
$context['posts_noticias'] = $post_noticias_data ['posts'];
|
||||
$context['pagination'] = $post_noticias_data['pagination'];
|
||||
|
||||
$servicios_data = $this->getSubpaginasServicios();
|
||||
$context['subpaginas_servicios'] = $servicios_data['subpaginas'];
|
||||
$context['pagination'] = $servicios_data['pagination'];
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
{% if videos %}
|
||||
<div id="videosCarousel" class="carousel slide" data-bs-ride="carousel">
|
||||
<div class="carousel-inner">
|
||||
{% for pair in videos|batch(2, null) %}
|
||||
{% for pair in videos.posts|batch(2, null) %}
|
||||
|
||||
<div class="carousel-item {% if loop.first %}active{% endif %}">
|
||||
<div class="row">
|
||||
@ -67,7 +67,7 @@
|
||||
</div>
|
||||
|
||||
{# carousel controls buttons#}
|
||||
{% if videos|length > 1 %}
|
||||
{% if videos.posts|length > 1 %}
|
||||
<button class="carousel-control-prev" type="button" data-bs-target="#videosCarousel" data-bs-slide="prev">
|
||||
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
|
||||
<span class="visually-hidden">Anterior</span>
|
||||
|
||||
@ -47,10 +47,11 @@
|
||||
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<h2>no hay artículos</h2>
|
||||
<p>{{ __('No hay artículos', 'Sindikatua') }}</p>
|
||||
{% endif %}
|
||||
|
||||
<!-- PAGINATION -->
|
||||
{% set pagination = posts_noticias.pagination %}
|
||||
<div class="pagination-custom mt-5">
|
||||
{% include 'partials/pagination-custom.twig' %}
|
||||
</div>
|
||||
|
||||
@ -4,11 +4,12 @@
|
||||
|
||||
{# Sección noticias #}
|
||||
{% if posts_noticias %}
|
||||
|
||||
<section class="recent-posts">
|
||||
<div class="row g-4 mt-3">
|
||||
{# Columna izquierda - Artículo principal #}
|
||||
<div class="col-md-8">
|
||||
{% set main_article = posts_noticias[0] %}
|
||||
{% set main_article = posts_noticias.posts[0] %}
|
||||
<div class="card main-article">
|
||||
<a href="{{ main_article.link }}">
|
||||
<img src="{{ main_article.thumbnail.src('medium') }}"
|
||||
@ -25,7 +26,7 @@
|
||||
{# Columna derecha - Dos artículos secundarios #}
|
||||
<div class="col-md-4">
|
||||
<div class="d-flex flex-column h-100 justify-content-between">
|
||||
{% for article in posts_noticias[1:2] %}
|
||||
{% for article in posts_noticias.posts[1:2] %}
|
||||
<div class="card secondary-article {% if loop.first %}media-mb{% endif %}">
|
||||
<a href="{{ article.link }}">
|
||||
<img src="{{ article.thumbnail.src('medium') }}"
|
||||
@ -42,6 +43,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% else %}
|
||||
no llega nada
|
||||
{% endif %}
|
||||
|
||||
{# Sección vídeos + Opinión #}
|
||||
|
||||
@ -13,32 +13,34 @@
|
||||
<div class="col-12 mb-2">
|
||||
<article>
|
||||
<div class="card">
|
||||
{% if pagina.thumbnail %}
|
||||
{#{% if pagina.thumbnail %}
|
||||
<img src="{{ pagina.thumbnail.src}}"
|
||||
alt="{{ pagina.thumbnail.alt }}"
|
||||
class="card-img-top">
|
||||
{% endif %}
|
||||
{% endif %} #}
|
||||
<div class="card-body">
|
||||
<a href="{{ pagina.link }}" class="text-decoration-none">
|
||||
<h5 href="{{ pagina.link }}" class="card-title fs-4 text-dark link-underline-animate">{{ pagina.title }}</h5>
|
||||
</a>
|
||||
{# <p class="card-text">{{ pagina.content }}</p> #}
|
||||
<p class="card-text"> {{
|
||||
<p class="card-text">{{ pagina.content }}</p>
|
||||
{# <p class="card-text"> {{
|
||||
pagina.excerpt({
|
||||
words: 50,
|
||||
read_more: ''
|
||||
})
|
||||
}}</p>
|
||||
}}</p>#}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>No hay subpáginas.</p>
|
||||
<p>{{ __('No hay artículos', 'Sindikatua') }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- PAGINATION -->
|
||||
{% set pagination = subpaginas_servicios.pagination %}
|
||||
|
||||
{% if pagination %}
|
||||
<div class="pagination-custom mt-5">
|
||||
{% include 'partials/pagination-custom.twig' %}
|
||||
@ -46,7 +48,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<p>No hay servicios disponibles en esta sección.</p>
|
||||
<p>{{ __('No hay artículos', 'Sindikatua') }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@ -59,6 +59,7 @@
|
||||
{% endif %}
|
||||
|
||||
<!-- PAGINATION -->
|
||||
{% set pagination = videos.pagination %}
|
||||
<div class="pagination-custom mt-5">
|
||||
{% include 'partials/pagination-custom.twig' %}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user