ADD Archive documentos
This commit is contained in:
@ -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.
|
||||
44
archive-documentos.php
Normal file
44
archive-documentos.php
Normal 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);
|
||||
@ -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() {
|
||||
|
||||
@ -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);
|
||||
@ -98,6 +98,14 @@ class StarterSite extends Site {
|
||||
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() {
|
||||
// add_rewrite_rule(
|
||||
@ -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();
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
<section class="documentos">
|
||||
<div class="container">
|
||||
{% if documentos %}
|
||||
{#<pre>{{ dump(documentos) }}</pre>#}
|
||||
|
||||
{% for doc in documentos %}
|
||||
<div class="card mb-3">
|
||||
@ -44,11 +43,13 @@
|
||||
{{ __('Ver documento', 'Sindikatua') }}
|
||||
</a>
|
||||
|
||||
<a href="{{ doc.documento_url }}" download
|
||||
<a href="{{ doc.documento_url() }}" download
|
||||
class="btn me-2 btn-primary-cnt btn-xs" >
|
||||
<i class="bi bi-cloud-download-fill"></i>
|
||||
{{ __('Descargar', 'Sindikatua') }}
|
||||
</a>
|
||||
{% else %}
|
||||
no hay doc.documento_url
|
||||
|
||||
{% endif %}
|
||||
|
||||
@ -60,9 +61,22 @@
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
No hay documentos disponibles.
|
||||
<p>{{ __('No hay documentos', 'Sindikatua') }}</p>
|
||||
</div>
|
||||
{% 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>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user