ADD Archive documentos

This commit is contained in:
2025-10-23 08:41:07 +00:00
parent e7eccfa10d
commit 096a268daa
5 changed files with 117 additions and 19 deletions

View File

@ -2,29 +2,26 @@
========================== ==========================
ARCHIVE PARA POST TYPE CREADOS ARCHIVE PARA POST TYPE CREADOS
Idiomas
> Ajustes > post type: marcar el post type.
> Traducciones. Filtrar por "Slugs de las URLs". Traducir las palabras clave
==========================
ACF ACF
> Tipos de contenido. Elegir el que quieres configurar. > Tipos de contenido. Elegir el que quieres configurar.
> Marcar archive y jerárquico. > Marcar archive (¿y jerárquico?)
> URLs añadir el nombre del slug (Ej: videos) > URLs añadir el nombre del slug (Ej: videos)
========================== ==========================
Crear archive-slug.php (Ej: archive-videos.php) IDIOMAS
> Ajustes > post type: marcar el post type.
> Traducciones. Filtrar por "Slugs de las URLs". Traducir las palabras clave.
==========================
>Crear archive-slug.php (Ej: archive-videos.php)
Si se quieren recibir todos los posts, independientemente del idioma. Ejemplo: >Si se quieren recibir todos los posts, independientemente del idioma.
Ejemplo:
> $context['videos'] = Timber::get_posts([ > $context['videos'] = Timber::get_posts([
'post_type' => 'videos',
'posts_per_page' => -1,
'lang' => '' // Importante: vacío para obtener todos 'lang' => '' // Importante: vacío para obtener todos
]); ]);
========================== ==========================
========================== ==========================
==========================
==========================
ARCHIVE PARA CATEGORIAS ARCHIVE PARA CATEGORIAS
> Ir a functions.php y añadir rutas (para cada idioma) > Ir a functions.php y añadir rutas (para cada idioma)
@ -35,4 +32,12 @@ ARCHIVE PARA CATEGORIAS
> >
> ¡OJO en el menú! Hay que ver si es subelemento para poner la ruta bien en el functions. > ¡OJO en el menú! Hay que ver si es subelemento para poner la ruta bien en el functions.
==========================
==========================
ISSUE botones idiomas
>Si todos los posts están en un idioma y en uno no hay posts, pollylang te lleva a la home al cambiar de idioma.
Ejemplo videos y documentos.
>Ir a StarterSite.php y buscar la función getPolylangData(). Al final de la función he metido
dos condiciones tanto para video como para documentos.

44
archive-documentos.php Normal file
View File

@ -0,0 +1,44 @@
<?php
/**
* Archive documentos
*/
$context = Timber::context();
$posts = Timber::get_posts([
'post_type' => 'documento',
'paged' => isset($params['paged']) ? $params['paged'] : 1,
'posts_per_page' => 10,
'lang' => '',
]);
$documentos = [];
foreach ($posts as $post) {
$archivo = get_field('documento', $post->ID);
$doc = [
'id' => $post->ID,
'title' => $post->title,
'link' => $post->link,
'content' => $post->content,
'excerpt' => $post->excerpt,
];
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;
}
$context['documentos'] = $documentos;
$context['posts'] = $posts;
error_log('✅ archive-documentos - Posts: ' . count($context['documentos']));
Timber::render('templates/page-documentos.twig', $context);

View File

@ -51,6 +51,23 @@ foreach(['/es/noticias/conflictos-laborales/page/:paged','/eu/berriak/lan-gatazk
}); });
} }
// Ruta para la página de 'documentos'
foreach(['/es/documentos','/eu/dokumentuak'] as $route) {
Routes::map($route, function($params){
$query = false;
Routes::load('archive-documentos.php', $params, $query, 200);
});
}
// Ruta para las páginas de paginación 'documentos'
foreach(['/es/documentos/page/:paged','/eu/dokumentuak/page/:paged'] as $route) {
Routes::map($route, function($params){
$query = false;
Routes::load('archive-documentos.php', $params, $query, 200);
});
}
// *************************DEBUGUEANDO................... // *************************DEBUGUEANDO...................
// add_shortcode('test_smtp_db', function() { // add_shortcode('test_smtp_db', function() {

View File

@ -85,7 +85,7 @@ class StarterSite extends Site {
}, 10, 2); }, 10, 2);
/** FIN *************POST "QUÉ ES LA CNT" */ /** FIN *************POST "QUÉ ES LA CNT" */
// archive-videos // paginación y todos los archivos sin tener en cuenta el idioma -> archive-videos
add_action('pre_get_posts', function($query) { add_action('pre_get_posts', function($query) {
if (!is_admin() && $query->is_main_query() && is_post_type_archive('videos')) { if (!is_admin() && $query->is_main_query() && is_post_type_archive('videos')) {
$query->set('posts_per_page', 16); $query->set('posts_per_page', 16);
@ -97,6 +97,14 @@ class StarterSite extends Site {
add_action('wp_ajax_get_page_content', [$this, 'get_page_content_ajax']); add_action('wp_ajax_get_page_content', [$this, 'get_page_content_ajax']);
add_action('wp_ajax_nopriv_get_page_content', [$this, 'get_page_content_ajax']); add_action('wp_ajax_nopriv_get_page_content', [$this, 'get_page_content_ajax']);
add_action('template_redirect', [$this, 'redirect_subpaginas_acerca']); add_action('template_redirect', [$this, 'redirect_subpaginas_acerca']);
// Tag añadido en CF7 formularios para saber qué ciudad es.
add_filter('wpcf7_form_tag', function($tag) {
if ($tag['name'] === 'title') {
$tag['values'][] = get_the_title();
}
return $tag;
}, 10, 1);
// *** SOLO USAR UNA VEZ PARA LIMPIAR. NO FUNCIONABA LA PAGINACIÓN DE SEARCH. // *** SOLO USAR UNA VEZ PARA LIMPIAR. NO FUNCIONABA LA PAGINACIÓN DE SEARCH.
// add_action('init', function() { // add_action('init', function() {
@ -105,10 +113,7 @@ class StarterSite extends Site {
// 'index.php?paged=$matches[1]', // 'index.php?paged=$matches[1]',
// 'top' // 'top'
// ); // );
// // Solo ejecuta una vez, luego comenta estas líneas
// error_log('✅ flush rewrite rules'); // error_log('✅ flush rewrite rules');
// flush_rewrite_rules(false); // flush_rewrite_rules(false);
// }, 10); // }, 10);
@ -314,6 +319,7 @@ 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. // 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')) { if (is_post_type_archive('videos')) {
error_log('archive videos');
foreach ($polylang_data['languages'] as $slug => &$lang) { foreach ($polylang_data['languages'] as $slug => &$lang) {
if ($slug === 'es') { if ($slug === 'es') {
$lang['url'] = home_url('/es/videos/'); $lang['url'] = home_url('/es/videos/');
@ -323,6 +329,18 @@ 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('documento')) {
error_log('archive documentos');
foreach ($polylang_data['languages'] as $slug => &$lang) {
if ($slug === 'es') {
$lang['url'] = home_url('/es/documentos/');
} elseif ($slug === 'eu') {
$lang['url'] = home_url('/eu/dokumentuak/');
}
}
}
return $polylang_data; return $polylang_data;
} }
@ -728,7 +746,7 @@ class StarterSite extends Site {
//Otras páginas //Otras páginas
$context['SubpaginasAcercaCnt'] = $this->getSubpaginasAcercaCnt(); $context['SubpaginasAcercaCnt'] = $this->getSubpaginasAcercaCnt();
//$context['paginas_acerca'] = $this->getPaginasAcerca(); //$context['paginas_acerca'] = $this->getPaginasAcerca();
$context['documentos'] = $this->getDocumentos(); //$context['documentos'] = $this->getDocumentos();
$context['enlaces'] = $this->getEnlaces(); $context['enlaces'] = $this->getEnlaces();
$context['contacto_info'] = $this->getContactoFields(); $context['contacto_info'] = $this->getContactoFields();
$context['posts_industry'] = $this->getPostIndustry(); $context['posts_industry'] = $this->getPostIndustry();

View File

@ -6,7 +6,6 @@
<section class="documentos"> <section class="documentos">
<div class="container"> <div class="container">
{% if documentos %} {% if documentos %}
{#<pre>{{ dump(documentos) }}</pre>#}
{% for doc in documentos %} {% for doc in documentos %}
<div class="card mb-3"> <div class="card mb-3">
@ -44,11 +43,13 @@
{{ __('Ver documento', 'Sindikatua') }} {{ __('Ver documento', 'Sindikatua') }}
</a> </a>
<a href="{{ doc.documento_url }}" download <a href="{{ doc.documento_url() }}" download
class="btn me-2 btn-primary-cnt btn-xs" > class="btn me-2 btn-primary-cnt btn-xs" >
<i class="bi bi-cloud-download-fill"></i> <i class="bi bi-cloud-download-fill"></i>
{{ __('Descargar', 'Sindikatua') }} {{ __('Descargar', 'Sindikatua') }}
</a> </a>
{% else %}
no hay doc.documento_url
{% endif %} {% endif %}
@ -60,9 +61,22 @@
{% endfor %} {% endfor %}
{% else %} {% else %}
<div class="alert alert-info" role="alert"> <div class="alert alert-info" role="alert">
No hay documentos disponibles. <p>{{ __('No hay documentos', 'Sindikatua') }}</p>
</div> </div>
{% endif %} {% endif %}
<!-- PAGINATION -->
{% set pagination = posts.pagination %}
{% if pagination %}
<div class="pagination-custom mt-5">
{% include 'partials/pagination-custom.twig' %}
</div>
{% else %}
<div class="alert alert-info" role="alert">
No hay paginación.
</div>
{% endif %}
</div> </div>
</section> </section>
{% endblock %} {% endblock %}