diff --git a/archive.md b/ARCHIVE.md similarity index 64% rename from archive.md rename to ARCHIVE.md index 865e01a..dfd55fb 100644 --- a/archive.md +++ b/ARCHIVE.md @@ -2,29 +2,26 @@ ========================== 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 > 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) ========================== -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([ - 'post_type' => 'videos', - 'posts_per_page' => -1, 'lang' => '' // Importante: vacío para obtener todos ]); ========================== ========================== -========================== -========================== ARCHIVE PARA CATEGORIAS > 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. +========================== +========================== +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. diff --git a/archive-documentos.php b/archive-documentos.php new file mode 100644 index 0000000..3e46f9d --- /dev/null +++ b/archive-documentos.php @@ -0,0 +1,44 @@ + '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); diff --git a/functions.php b/functions.php index ce27cc0..2452eba 100644 --- a/functions.php +++ b/functions.php @@ -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................... // add_shortcode('test_smtp_db', function() { diff --git a/src/StarterSite.php b/src/StarterSite.php index 760e5c6..788569a 100644 --- a/src/StarterSite.php +++ b/src/StarterSite.php @@ -85,7 +85,7 @@ class StarterSite extends Site { }, 10, 2); /** 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) { if (!is_admin() && $query->is_main_query() && is_post_type_archive('videos')) { $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_nopriv_get_page_content', [$this, 'get_page_content_ajax']); 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. // add_action('init', function() { @@ -105,10 +113,7 @@ class StarterSite extends Site { // 'index.php?paged=$matches[1]', // 'top' // ); - - // // Solo ejecuta una vez, luego comenta estas líneas // error_log('✅ flush rewrite rules'); - // flush_rewrite_rules(false); // }, 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. if (is_post_type_archive('videos')) { + error_log('archive videos'); foreach ($polylang_data['languages'] as $slug => &$lang) { if ($slug === 'es') { $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; } @@ -728,7 +746,7 @@ class StarterSite extends Site { //Otras páginas $context['SubpaginasAcercaCnt'] = $this->getSubpaginasAcercaCnt(); //$context['paginas_acerca'] = $this->getPaginasAcerca(); - $context['documentos'] = $this->getDocumentos(); + //$context['documentos'] = $this->getDocumentos(); $context['enlaces'] = $this->getEnlaces(); $context['contacto_info'] = $this->getContactoFields(); $context['posts_industry'] = $this->getPostIndustry(); diff --git a/views/templates/page-documentos.twig b/views/templates/page-documentos.twig index 26243d4..56c9e1f 100644 --- a/views/templates/page-documentos.twig +++ b/views/templates/page-documentos.twig @@ -6,7 +6,6 @@
{% if documentos %} - {#
{{ dump(documentos) }}
#} {% for doc in documentos %}
@@ -44,11 +43,13 @@ {{ __('Ver documento', 'Sindikatua') }} - {{ __('Descargar', 'Sindikatua') }} + {% else %} + no hay doc.documento_url {% endif %} @@ -60,9 +61,22 @@ {% endfor %} {% else %} {% endif %} + + + {% set pagination = posts.pagination %} + {% if pagination %} +
+ {% include 'partials/pagination-custom.twig' %} +
+ {% else %} + + {% endif %} +
{% endblock %}