Refactorizacion servicios & industria

This commit is contained in:
2025-10-28 09:17:55 +00:00
parent 8b1b8e8a62
commit a7e2583ea9
6 changed files with 24 additions and 166 deletions

View File

@@ -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();