Refactorizacion servicios & industria
This commit is contained in:
20
page.php
20
page.php
@ -8,11 +8,6 @@
|
||||
* different template.
|
||||
*/
|
||||
|
||||
/**namespace App;
|
||||
use Timber\Timber;
|
||||
$context = Timber::context();
|
||||
Timber::render( 'templates/page.twig', $context );*/
|
||||
|
||||
$context = Timber::context();
|
||||
$timber_post = Timber::get_post();
|
||||
$context['post'] = $timber_post;
|
||||
@ -21,14 +16,7 @@ $context['search_query'] = get_search_query();
|
||||
//Timber::render( array( 'templates/page-' . $timber_post->slug . '.twig', 'page.twig' ), $context );
|
||||
$parent = $timber_post->parent;
|
||||
|
||||
// Verificar si es una subpágina de servicios
|
||||
$cast_subpagina_servicios = ($parent && ($parent->slug === 'servicios-privados' || $parent->slug === 'servicios-publicos'));
|
||||
$eusk_subpagina_zerbitzu = ($parent && ($parent->slug === 'zerbitzu-pribatuak' || $parent->slug === 'zerbitzu-publikoak'));
|
||||
$subpagina_industria = ($parent && ($parent->slug === 'industria'));
|
||||
|
||||
$slug_actual = $timber_post->slug;
|
||||
|
||||
//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');
|
||||
|
||||
if ($parent && ($parent->slug === 'contactos' || $parent->slug === 'kontaktua') ) {
|
||||
@ -37,12 +25,6 @@ if ($parent && ($parent->slug === 'contactos' || $parent->slug === 'kontaktua')
|
||||
} elseif ($pagina_servicios) {
|
||||
error_log('✅ (page.php) Página Servicios: ' . $slug_actual);
|
||||
Timber::render('templates/page-servicios.twig', $context);
|
||||
} elseif ( $cast_subpagina_servicios || $eusk_subpagina_zerbitzu ) {
|
||||
error_log('✅ (page.php) Página "single-servicios": ' . $parent->slug);
|
||||
Timber::render('templates/single-servicios.twig', $context);
|
||||
} elseif ( $subpagina_industria ) {
|
||||
//error_log('✅ (page.php) Página "Industria": ' . $parent->slug);
|
||||
Timber::render('templates/single-industria.twig', $context);
|
||||
} elseif ( $slug_actual === 'noticias' || $slug_actual === 'berriak') {
|
||||
error_log('🔴 (page.php) Página noticias - ERROR');
|
||||
} elseif ($parent && ($parent->slug == 'acerca-de-la-cnt' || $parent->slug == 'cnt-ri-buruz') ) {
|
||||
@ -51,6 +33,6 @@ if ($parent && ($parent->slug === 'contactos' || $parent->slug === 'kontaktua')
|
||||
$context['post'] = $timber_post->parent;
|
||||
Timber::render(array('templates/page-acerca-de-la-cnt.twig'), $context);
|
||||
} else {
|
||||
// error_log('✅ (page.php) Página General: ' . $timber_post->slug);
|
||||
error_log('✅ (page.php) Página General: ' . $timber_post->slug);
|
||||
Timber::render(array('templates/page-' . $timber_post->slug . '.twig', 'templates/page.twig'), $context);
|
||||
}
|
||||
@ -290,7 +290,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 documnentos 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) {
|
||||
@ -405,99 +405,13 @@ class StarterSite extends Site {
|
||||
return $grupos;
|
||||
}
|
||||
|
||||
//Which paths is for 'servicios'
|
||||
public function whichPathIs() {
|
||||
$current_post = get_post();
|
||||
$slug_actual = $current_post->post_name;
|
||||
|
||||
// Determinar qué página padre buscar según el slug actual
|
||||
if ($slug_actual === 'servicios-publicos') {
|
||||
$path = 'accion-sindical/servicios-publicos';
|
||||
$tipo = 'publicos';
|
||||
} elseif ($slug_actual === 'servicios-privados') {
|
||||
$path = 'accion-sindical/servicios-privados';
|
||||
$tipo = 'privados';
|
||||
} elseif ($slug_actual === 'zerbitzu-publikoak') {
|
||||
$path = 'ekintza-sindikala/zerbitzu-publikoak';
|
||||
$tipo = 'publikoak';
|
||||
} elseif ($slug_actual === 'zerbitzu-pribatuak') {
|
||||
$path = 'ekintza-sindikala/zerbitzu-pribatuak';
|
||||
$tipo = 'pribatuak';
|
||||
} else {
|
||||
return [
|
||||
'path' => null,
|
||||
'tipo' => null,
|
||||
'found' => false
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'path' => $path,
|
||||
'tipo' => $tipo,
|
||||
'found' => true
|
||||
];
|
||||
}
|
||||
|
||||
/** Servicios públicos y privados */
|
||||
private function getSubpaginasServicios() {
|
||||
|
||||
$pathInfo = $this->whichPathIs();
|
||||
|
||||
// Si no encontramos una página válida, retornar vacío
|
||||
if (!$pathInfo['found']) {
|
||||
return [
|
||||
'subpaginas' => [],
|
||||
'pagination_Servicios' => null
|
||||
];
|
||||
}
|
||||
|
||||
$full_path = $pathInfo['path'];
|
||||
$pag_servicios = get_page_by_path($full_path);
|
||||
|
||||
if (!$pag_servicios) {
|
||||
error_log("🔴 Página '$pathTipo.$path' no encontrada.");
|
||||
return [
|
||||
'subpaginas' => [],
|
||||
'pagination_Servicios' => null
|
||||
];
|
||||
}
|
||||
|
||||
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // Obtener el número de página actual
|
||||
$posts_per_page = 6;
|
||||
|
||||
global $wp_query; // Guardar la query global actual
|
||||
$temp_query = $wp_query;
|
||||
|
||||
$wp_query = new \WP_Query([ // Crear nueva WP_Query
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_parent' => $pag_servicios->ID,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => $posts_per_page,
|
||||
'paged' => $paged,
|
||||
]);
|
||||
|
||||
$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 = $pathInfo['tipo'];
|
||||
}
|
||||
|
||||
$pagination = new \Timber\Pagination($wp_query->max_num_pages); // Crear objeto de paginación
|
||||
$wp_query = $temp_query; // Restaurar query original
|
||||
|
||||
return $subpaginas;
|
||||
|
||||
}
|
||||
|
||||
public function getContactoFields() {
|
||||
|
||||
$post = Timber::get_post();
|
||||
|
||||
if (!$post) { return []; }
|
||||
|
||||
$form_shortcode = get_field('etiqueta_formulario', $post->ID); // o el campo ACF donde esté el shortcode
|
||||
$form_shortcode = get_field('etiqueta_formulario', $post->ID);
|
||||
//error_log('✅ ID Página "Contactos": ' . $post->ID);
|
||||
|
||||
$contactsFields = [
|
||||
@ -512,35 +426,6 @@ class StarterSite extends Site {
|
||||
];
|
||||
|
||||
return $contactsFields;
|
||||
|
||||
}
|
||||
|
||||
private function getPostIndustry() {
|
||||
|
||||
$pag_industry = get_page_by_path('accion-sindical/industria');
|
||||
|
||||
if (!$pag_industry) {
|
||||
error_log('🔴 Página "Industria" no encontrada.');
|
||||
return [];
|
||||
} else {
|
||||
//error_log('✅ Página "Industria" encontrada.');
|
||||
}
|
||||
|
||||
$subpaginas = Timber::get_posts([
|
||||
'post_type' => 'page',
|
||||
'post_status' => 'publish',
|
||||
'post_parent' => $pag_industry->ID,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => -1,
|
||||
]);
|
||||
|
||||
foreach ($subpaginas as $pagina) {
|
||||
//$pagina->imagen = $pagina->thumbnail ? $pagina->thumbnail->src('medium') : null;
|
||||
$pagina->thumbnail= get_the_post_thumbnail_url($pagina->ID);
|
||||
}
|
||||
|
||||
return $subpaginas;
|
||||
}
|
||||
|
||||
private function getListContacts() {
|
||||
@ -581,11 +466,6 @@ class StarterSite extends Site {
|
||||
//Otras páginas
|
||||
$context['enlaces'] = $this->getEnlaces();
|
||||
$context['contacto_info'] = $this->getContactoFields();
|
||||
$context['posts_industry'] = $this->getPostIndustry();
|
||||
// $context['subpaginas_servicios'] = \Timber\Helper::transient('subpaginas_servicios2', function () {
|
||||
// return $this->getSubpaginasServicios();
|
||||
// }, 3600);
|
||||
$context['subpaginas_servicios'] = $this->getSubpaginasServicios();
|
||||
|
||||
//Para Footer
|
||||
$context['lasts_posts_news'] = $this->getLastsPostsNews();
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
<link rel="author" href="{{ site.theme.link }}/humans.txt" />
|
||||
<link rel="profile" href="http://gmpg.org/xfn/11" />
|
||||
<script src="https://unpkg.com/@popperjs/core@2"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.8/dist/htmx.min.js"></script>
|
||||
{% do action('get_header') %}
|
||||
{{ function('wp_head') }}
|
||||
</head>
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.8/dist/htmx.min.js"></script>
|
||||
|
||||
<p class="mb-5 position-relative fs-4 fw-bold sp-module-title">{{ post.title }}</p>
|
||||
{# {{ dump(post.children) }} #}
|
||||
|
||||
@ -3,12 +3,13 @@
|
||||
{% block content %}
|
||||
<h1 class="my-5 position-relative fs-3 fw-bold sp-module-title">{{ post.title }}</h1>
|
||||
|
||||
<section class="section-industria">
|
||||
{% if posts_industry |length > 0 %}
|
||||
{% for noticias in posts_industry %}
|
||||
|
||||
{% set imagen = noticias.thumbnail.src | default(imagen_default) %}
|
||||
{% set alt = noticias.thumbnail.alt | default('Imagen por defecto') %}
|
||||
<section class="section-industria">
|
||||
{% if post.children('page') |length > 0 %}
|
||||
{% for subpagIndustria in post.children('page') %}
|
||||
|
||||
{% set imagen = subpagIndustria.thumbnail.src | default(imagen_default) %}
|
||||
{% set alt = subpagIndustria.thumbnail.alt | default('Imagen por defecto') %}
|
||||
|
||||
<div class="card my-3 position-relative posts-noticias">
|
||||
<div class="row g-0">
|
||||
@ -19,8 +20,8 @@
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title-text fs-4 fw-bold border-dark border-bottom">{{ noticias.title }}</h5>
|
||||
<p class="card-text"> {{noticias.content}}</p>
|
||||
<h5 class="card-title-text fs-4 fw-bold border-dark border-bottom">{{ subpagIndustria.title }}</h5>
|
||||
<p class="card-text"> {{subpagIndustria.content}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -31,12 +32,12 @@
|
||||
<p>{{ __('No hay artículos', 'Sindikatua') }}</p>
|
||||
{% endif %}
|
||||
|
||||
<!-- PAGINATION -->
|
||||
{% if pagination %}
|
||||
<!-- NO HAY PAGINATION -->
|
||||
{# {% if pagination %}
|
||||
<div class="pagination-custom mt-5">
|
||||
{% include 'partials/pagination-custom.twig' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %} #}
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
@ -3,17 +3,12 @@
|
||||
{% block content %}
|
||||
<h1 class="my-5 position-relative fs-3 fw-bold sp-module-title">{{ post.title }}</h1>
|
||||
|
||||
|
||||
{# {% for pagina in post.children('page') %}
|
||||
{{ pagina.title }}
|
||||
{% endfor %} #}
|
||||
|
||||
<section class="section-servicios">
|
||||
{% if subpaginas_servicios |length > 0 %}
|
||||
{% for noticias in subpaginas_servicios %}
|
||||
{% if post.children('page') |length > 0 %}
|
||||
{% for SubpagServicio in post.children('page') %}
|
||||
|
||||
{% set imagen = noticias.thumbnail.src | default(imagen_default) %}
|
||||
{% set alt = noticias.thumbnail.alt | default('Imagen por defecto') %}
|
||||
{% set imagen = SubpagServicio.thumbnail.src | default(imagen_default) %}
|
||||
{% set alt = SubpagServicio.thumbnail.alt | default('Imagen por defecto') %}
|
||||
|
||||
<div class="card my-3 position-relative posts-noticias">
|
||||
<div class="row g-0">
|
||||
@ -24,8 +19,8 @@
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title-text fs-4 fw-bold border-dark border-bottom">{{ noticias.title }}</h5>
|
||||
<p class="card-text"> {{noticias.content}}</p>
|
||||
<h5 class="card-title-text fs-4 fw-bold border-dark border-bottom">{{ SubpagServicio.title }}</h5>
|
||||
<p class="card-text"> {{SubpagServicio.content}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -36,13 +31,13 @@
|
||||
<p>{{ __('No hay artículos', 'Sindikatua') }}</p>
|
||||
{% endif %}
|
||||
|
||||
<!-- PAGINATION -->
|
||||
{% set pagination = subpaginas_servicios.pagination %}
|
||||
<!-- NO HAY PAGINATION -->
|
||||
{# {% set pagination = post.children.pagination %}
|
||||
{% if pagination %}
|
||||
<div class="pagination-custom mt-5">
|
||||
{% include 'partials/pagination-custom.twig' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %} #}
|
||||
|
||||
</section>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user