MODIF backend segundo idioma
This commit is contained in:
@ -33,7 +33,16 @@ class StarterSite extends Site {
|
|||||||
add_filter('timber/context', [$this, 'add_global_context']); // variables globales
|
add_filter('timber/context', [$this, 'add_global_context']); // variables globales
|
||||||
add_filter('timber/twig', [$this, 'add_videos_embed_to_twig']); //videos embed
|
add_filter('timber/twig', [$this, 'add_videos_embed_to_twig']); //videos embed
|
||||||
add_action('pre_get_posts', array($this, 'exclude_pages_from_search')); //exclude pages with ACF
|
add_action('pre_get_posts', array($this, 'exclude_pages_from_search')); //exclude pages with ACF
|
||||||
|
|
||||||
|
add_action('init', function() {
|
||||||
|
if (function_exists('pll_current_language')) {
|
||||||
|
// Forzar que ACF reconozca el idioma actual
|
||||||
|
add_filter('acf/settings/current_language', function() {
|
||||||
|
return pll_current_language();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,13 +213,23 @@ class StarterSite extends Site {
|
|||||||
return $file_types;
|
return $file_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
//section "portada"
|
//section "portada> ENLACES"
|
||||||
private function getBotonesImagen() {
|
private function getBotonesImagen($page_id = null) {
|
||||||
|
|
||||||
|
if (is_null($page_id)) {
|
||||||
|
$page_id = get_the_ID();
|
||||||
|
// Si estamos en euskera, obtener la página en español
|
||||||
|
if (pll_current_language() == 'eu') {
|
||||||
|
$spanish_page_id = pll_get_post($page_id, 'es');
|
||||||
|
$page_id = $spanish_page_id ?: $page_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$botones = [];
|
$botones = [];
|
||||||
|
|
||||||
for ($i = 1; $i <= 4; $i++) {
|
for ($i = 1; $i <= 4; $i++) {
|
||||||
$imagen = get_field('imagen_boton_' . $i);
|
$imagen = get_field('imagen_boton_' . $i, $page_id);
|
||||||
$enlace = get_field('enlace_boton_' . $i);
|
$enlace = get_field('enlace_boton_' . $i, $page_id);
|
||||||
|
|
||||||
$botones[] = [
|
$botones[] = [
|
||||||
'imagen' => $imagen,
|
'imagen' => $imagen,
|
||||||
@ -255,7 +274,7 @@ class StarterSite extends Site {
|
|||||||
for ($i = 1; $i <= $max_logos; $i++) {
|
for ($i = 1; $i <= $max_logos; $i++) {
|
||||||
$logoHeader = get_field('logo_header_' . $i, 'option');
|
$logoHeader = get_field('logo_header_' . $i, 'option');
|
||||||
$textoHeader = get_field('texto_header_' . $i, 'option');
|
$textoHeader = get_field('texto_header_' . $i, 'option');
|
||||||
|
|
||||||
if ($logoHeader || $textoHeader) {
|
if ($logoHeader || $textoHeader) {
|
||||||
$logos[] = [
|
$logos[] = [
|
||||||
'logo' => $logoHeader,
|
'logo' => $logoHeader,
|
||||||
@ -285,6 +304,49 @@ class StarterSite extends Site {
|
|||||||
'orderby' => 'date',
|
'orderby' => 'date',
|
||||||
'order' => 'DESC'
|
'order' => 'DESC'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// $current_lang = pll_current_language();
|
||||||
|
|
||||||
|
// // Consulta con filtro de idioma
|
||||||
|
// $posts = Timber::get_posts([
|
||||||
|
// 'post_type' => 'opinion',
|
||||||
|
// 'posts_per_page' => 1,
|
||||||
|
// 'post_status' => 'publish',
|
||||||
|
// 'orderby' => 'date',
|
||||||
|
// 'order' => 'DESC',
|
||||||
|
// 'lang' => $current_lang // ← Filtro por idioma
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// // Debug temporal - quítalo después
|
||||||
|
// $debug_all = Timber::get_posts([
|
||||||
|
// 'post_type' => 'opinion',
|
||||||
|
// 'posts_per_page' => -1,
|
||||||
|
// 'post_status' => 'publish'
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// $debug_spanish = Timber::get_posts([
|
||||||
|
// 'post_type' => 'opinion',
|
||||||
|
// 'posts_per_page' => -1,
|
||||||
|
// 'post_status' => 'publish',
|
||||||
|
// 'lang' => 'es'
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// $debug_euskera = Timber::get_posts([
|
||||||
|
// 'post_type' => 'opinion',
|
||||||
|
// 'posts_per_page' => -1,
|
||||||
|
// 'post_status' => 'publish',
|
||||||
|
// 'lang' => 'eu'
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// // Logging temporal
|
||||||
|
// error_log("=== DEBUG ARTICULOS OPINION ===");
|
||||||
|
// error_log("Idioma actual: " . $current_lang);
|
||||||
|
// error_log("Total artículos opinion: " . count($debug_all));
|
||||||
|
// error_log("Artículos en español: " . count($debug_spanish));
|
||||||
|
// error_log("Artículos en euskera: " . count($debug_euskera));
|
||||||
|
// error_log("Resultado consulta actual: " . count($posts));
|
||||||
|
|
||||||
|
// return $posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCampanaArticles() {
|
private function getCampanaArticles() {
|
||||||
@ -355,32 +417,35 @@ class StarterSite extends Site {
|
|||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'orderby' => 'menu_order',
|
'orderby' => 'menu_order',
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Obtiene los "Documentos"
|
||||||
private function getDocumentos() {
|
private function getDocumentos() {
|
||||||
|
|
||||||
$posts = Timber::get_posts([
|
$args = ([
|
||||||
'post_type' => 'documento',
|
'post_type' => 'documento',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
'orderby' => 'menu_order',
|
'orderby' => 'menu_order',
|
||||||
'order' => 'ASC',
|
'order' => 'ASC',
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
|
'lang' => '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//error_log('✅ Número de posts "Documentos" encontrados: ' . count($posts));
|
//error_log('✅ Número de posts "Documentos" encontrados: ' . count($posts));
|
||||||
|
$posts = Timber::get_posts($args);
|
||||||
|
|
||||||
$documentos = [];
|
$documentos = [];
|
||||||
|
|
||||||
foreach ($posts as $post) {
|
foreach ($posts as $post) {
|
||||||
$doc = [
|
$doc = [
|
||||||
'id' => $post->ID,
|
'id' => $post->ID,
|
||||||
'title' => $post->title,
|
'title' => $post->title,
|
||||||
'link' => $post->link,
|
'link' => $post->link,
|
||||||
'content' => $post->content,
|
'content' => $post->content,
|
||||||
'excerpt' => $post->excerpt,
|
'excerpt' => $post->excerpt,
|
||||||
|
'lang' => pll_get_post_language($post->ID),
|
||||||
];
|
];
|
||||||
|
|
||||||
$archivo = get_field('documento', $post->ID);
|
$archivo = get_field('documento', $post->ID);
|
||||||
@ -399,14 +464,14 @@ class StarterSite extends Site {
|
|||||||
return $documentos;
|
return $documentos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Obetiene campos de "Enlaces" */
|
||||||
* Obtiene los grupos de enlaces de la página "Enlaces"
|
|
||||||
*/
|
|
||||||
private function getEnlaces() {
|
private function getEnlaces() {
|
||||||
$grupos = [];
|
$grupos = [];
|
||||||
|
|
||||||
// Buscar página por su slug
|
// Buscar página por su slug & Cambia dinámicamente según idioma
|
||||||
$page = get_page_by_path('enlaces');
|
$page = get_page_by_path( pll_current_language() === 'eu' ? 'loturak' : 'enlaces' );
|
||||||
|
//error_log('✅ Página "enlaces" encontrada con ID: ' . $page->ID);
|
||||||
|
|
||||||
|
|
||||||
if (!$page) {
|
if (!$page) {
|
||||||
error_log('🔴 Página "enlaces" no encontrada con get_page_by_path().');
|
error_log('🔴 Página "enlaces" no encontrada con get_page_by_path().');
|
||||||
@ -425,7 +490,6 @@ class StarterSite extends Site {
|
|||||||
|
|
||||||
$field = get_field('grupos_enlaces', $page->ID);
|
$field = get_field('grupos_enlaces', $page->ID);
|
||||||
//error_log('📦 Contenido de get_field: ' . print_r($field, true));
|
//error_log('📦 Contenido de get_field: ' . print_r($field, true));
|
||||||
//error_log('✅ Página "enlaces" encontrada con ID: ' . $page->ID);
|
|
||||||
|
|
||||||
while (have_rows('grupos_enlaces', $page->ID)) {
|
while (have_rows('grupos_enlaces', $page->ID)) {
|
||||||
the_row();
|
the_row();
|
||||||
@ -473,6 +537,8 @@ class StarterSite extends Site {
|
|||||||
if (!$pag_servicios_publicos) {
|
if (!$pag_servicios_publicos) {
|
||||||
error_log('🔴 Página "Servicios públicos" no encontrada.');
|
error_log('🔴 Página "Servicios públicos" no encontrada.');
|
||||||
return [];
|
return [];
|
||||||
|
} else {
|
||||||
|
//error_log('✅ Página "Servicios públicos" encontrada.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$subpaginas = Timber::get_posts([
|
$subpaginas = Timber::get_posts([
|
||||||
@ -500,6 +566,8 @@ class StarterSite extends Site {
|
|||||||
if (!$pag_servicios_privados) {
|
if (!$pag_servicios_privados) {
|
||||||
error_log('🔴 Página "Servicios privados" no encontrada.');
|
error_log('🔴 Página "Servicios privados" no encontrada.');
|
||||||
return [];
|
return [];
|
||||||
|
} else {
|
||||||
|
//error_log('✅ Página "Servicios privados" encontrada.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$subpaginas = Timber::get_posts([
|
$subpaginas = Timber::get_posts([
|
||||||
@ -519,9 +587,57 @@ class StarterSite extends Site {
|
|||||||
return $subpaginas;
|
return $subpaginas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getSubpaginasServicios() {
|
||||||
|
// Detectar automáticamente si es servicios públicos o privados
|
||||||
|
$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';
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$pag_servicios = get_page_by_path($path);
|
||||||
|
if (!$pag_servicios) {
|
||||||
|
error_log("🔴 Página '$path' no encontrada.");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$subpaginas = Timber::get_posts([
|
||||||
|
'post_type' => 'page',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'post_parent' => $pag_servicios->ID,
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC',
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
foreach ($subpaginas as $pagina) {
|
||||||
|
$pagina->thumbnail = get_the_post_thumbnail_url($pagina->ID);
|
||||||
|
$pagina->tipo_servicio = $tipo; // Para usar en la plantilla si necesitas distinguir
|
||||||
|
}
|
||||||
|
|
||||||
|
return $subpaginas;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Campos de contactos
|
||||||
public function getContactoFields() {
|
public function getContactoFields() {
|
||||||
$post = Timber::get_post();
|
$post = Timber::get_post();
|
||||||
|
|
||||||
|
if (!$post) {
|
||||||
|
error_log('🔴 No hay páginas de contactos.');
|
||||||
|
return []; // devolver un array vacío para evitar el error
|
||||||
|
}
|
||||||
|
|
||||||
$form_shortcode = get_field('etiqueta_formulario', $post->ID); // o el campo ACF donde esté el shortcode
|
$form_shortcode = get_field('etiqueta_formulario', $post->ID); // o el campo ACF donde esté el shortcode
|
||||||
|
//error_log('✅ ID Página "Contactos": ' . $post->ID);
|
||||||
|
|
||||||
|
|
||||||
$contactsFields = [
|
$contactsFields = [
|
||||||
'nombre' => get_field('nombre_contacto', $post->ID),
|
'nombre' => get_field('nombre_contacto', $post->ID),
|
||||||
@ -538,23 +654,7 @@ class StarterSite extends Site {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAfiliateFields() {
|
// Excluir páginas de la búsqueda
|
||||||
$post = Timber::get_post();
|
|
||||||
|
|
||||||
|
|
||||||
$afiliateFields = [
|
|
||||||
'imagen_afiliate' => get_field('imagen_afiliate', $post->ID),
|
|
||||||
'enlace_boton_afiliate' => get_field('enlace_boton_afiliate', $post->ID),
|
|
||||||
'texto_boton' => get_field('texto_boton', $post->ID),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (empty($afiliateFields['imagen_afiliate']) && empty($afiliateFields['enlace_boton_afiliate'])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $afiliateFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function exclude_pages_from_search($query) {
|
public function exclude_pages_from_search($query) {
|
||||||
if (!is_admin() && $query->is_main_query() && $query->is_search()) {
|
if (!is_admin() && $query->is_main_query() && $query->is_search()) {
|
||||||
$query->set('meta_query', array(
|
$query->set('meta_query', array(
|
||||||
@ -572,6 +672,38 @@ class StarterSite extends Site {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Añadir idiomas de Polylang
|
||||||
|
private function getPolylangData() {
|
||||||
|
$polylang_data = array();
|
||||||
|
|
||||||
|
if (function_exists('pll_the_languages')) {
|
||||||
|
// Idiomas con toda la información
|
||||||
|
$polylang_data['languages'] = pll_the_languages(array(
|
||||||
|
'raw' => 1,
|
||||||
|
'hide_if_no_translation' => 0,
|
||||||
|
'show_flags' => 1,
|
||||||
|
'show_names' => 1
|
||||||
|
));
|
||||||
|
|
||||||
|
// Información del idioma actual
|
||||||
|
$polylang_data['current_language'] = pll_current_language();
|
||||||
|
$polylang_data['current_language_name'] = pll_current_language('name');
|
||||||
|
$polylang_data['default_language'] = pll_default_language();
|
||||||
|
|
||||||
|
// DEBUG: Escribir en el log de errores
|
||||||
|
//error_log('Languages: ' . print_r($polylang_data['languages'], true));
|
||||||
|
//error_log('Current language: ' . $polylang_data['current_language']);
|
||||||
|
//error_log('Default language: ' . $polylang_data['default_language']);
|
||||||
|
|
||||||
|
// URLs de home para cada idioma
|
||||||
|
$polylang_data['home_urls'] = array();
|
||||||
|
foreach ($polylang_data['languages'] as $lang) {
|
||||||
|
$polylang_data['home_urls'][$lang['slug']] = $lang['url'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $polylang_data;
|
||||||
|
}
|
||||||
|
|
||||||
//Global variables
|
//Global variables
|
||||||
public function add_global_context($context) {
|
public function add_global_context($context) {
|
||||||
@ -579,7 +711,7 @@ class StarterSite extends Site {
|
|||||||
$context['footer_1'] = get_field('footer_text_1', 'option');
|
$context['footer_1'] = get_field('footer_text_1', 'option');
|
||||||
$context['footer_2'] = get_field('footer_text_2', 'option');
|
$context['footer_2'] = get_field('footer_text_2', 'option');
|
||||||
$context['recent_posts_noticias'] = $this->recentPostsNews();
|
$context['recent_posts_noticias'] = $this->recentPostsNews();
|
||||||
$context['botones_imagen'] = $this->getBotonesImagen();
|
$context['botones_imagen'] = $this->getBotonesImagen(); //ENLACES
|
||||||
$context['redes_sociales'] = $this->getIconsRRSS();
|
$context['redes_sociales'] = $this->getIconsRRSS();
|
||||||
$context['logos_header'] = $this->getLogosHeader();
|
$context['logos_header'] = $this->getLogosHeader();
|
||||||
$context['videos'] = $this->getVideos();
|
$context['videos'] = $this->getVideos();
|
||||||
@ -591,7 +723,9 @@ class StarterSite extends Site {
|
|||||||
$context['subpaginas_servicios_publicos'] = $this->getPaginasServiciosPublicos();
|
$context['subpaginas_servicios_publicos'] = $this->getPaginasServiciosPublicos();
|
||||||
$context['subpaginas_servicios_privados'] = $this->getPaginasServiciosPrivados();
|
$context['subpaginas_servicios_privados'] = $this->getPaginasServiciosPrivados();
|
||||||
$context['contacto_info'] = $this->getContactoFields();
|
$context['contacto_info'] = $this->getContactoFields();
|
||||||
$context['afiliate_fields'] = $this->getAfiliateFields();
|
//$context['afiliate_fields'] = $this->getAfiliateFields();
|
||||||
|
$context = array_merge($context, $this->getPolylangData());
|
||||||
|
$context['subpaginas_servicios'] = $this->getSubpaginasServicios();
|
||||||
|
|
||||||
return $context;
|
return $context;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user