refactor acerca de

This commit is contained in:
2025-10-27 11:27:41 +00:00
parent e222a9166d
commit 961f892baf
3 changed files with 26 additions and 137 deletions

View File

@ -18,34 +18,39 @@ $timber_post = Timber::get_post();
$context['post'] = $timber_post;
$context['search_query'] = get_search_query();
//Timber::render( array( 'templates/page-' . $timber_post->post_name . '.twig', 'page.twig' ), $context );
//Timber::render( array( 'templates/page-' . $timber_post->slug . '.twig', 'page.twig' ), $context );
$parent = $timber_post->parent;
$parent = get_post($timber_post->post_parent);
// Verificar si es una subpágina de servicios
$cast_subpagina_servicios = ($parent && ($parent->post_name === 'servicios-privados' || $parent->post_name === 'servicios-publicos'));
$eusk_subpagina_zerbitzu = ($parent && ($parent->post_name === 'zerbitzu-pribatuak' || $parent->post_name === 'zerbitzu-publikoak'));
$subpagina_industria = ($parent && ($parent->post_name === 'industria'));
$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;
$slug_actual = $timber_post->post_name;
//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->post_name === 'contactos' || $parent->post_name === 'kontaktua') ) {
if ($parent && ($parent->slug === 'contactos' || $parent->slug === 'kontaktua') ) {
// subpáginas de contactos
Timber::render('templates/page-contactos.twig', $context);
} 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->post_name);
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->post_name);
//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') ) {
$context['es_subpagina'] = true;
$context['subpagina'] = $timber_post;
$context['post'] = $timber_post->parent;
Timber::render(array('templates/page-acerca-de-la-cnt.twig'), $context);
} else {
error_log('✅ (page.php) Página General: ' . $parent->post_name);
Timber::render(array('templates/page-' . $timber_post->post_name . '.twig'), $context);
// error_log('✅ (page.php) Página General: ' . $timber_post->slug);
Timber::render(array('templates/page-' . $timber_post->slug . '.twig', 'templates/page.twig'), $context);
}

View File

@ -9,6 +9,8 @@ namespace App;
use Timber\Site;
use Timber\Timber;
use Timber\Request;
use Twig\Environment;
use Twig\TwigFilter;
@ -44,47 +46,6 @@ class StarterSite extends Site {
}
});
/** ***************** ACERCA DE - POST "QUÉ ES LA CNT" */
// Previene borrar el post "Qué es la cnt" porque forma parte del menú //
$ids_especiales = [10982, 4791, 10981];
define('POST_ESPECIAL_TYPE', 'acerca');
// Añadir clase personalizada al tr del listado de posts
add_filter('post_class', function($classes, $class, $post_id) use ($ids_especiales) {
if (in_array($post_id, $ids_especiales)) {
$classes[] = 'post-especial';
}
return $classes;
}, 10, 3);
// Añadir estilo en el admin a los "ids_especiales"
add_action('admin_head', function() use ($ids_especiales) {
if (empty($ids_especiales)) return;
$css = '';
foreach ($ids_especiales as $id) {
$css .= "tr#post-$id td { background-color: #fffae6 !important; border-top: 2px solid #f0c000 !important; }";
}
echo "<style>$css</style>";
});
// Ocultar el enlace "Mover a la papelera" en el listado
add_filter('post_row_actions', function($actions, $post) use ($ids_especiales) {
if ($post->post_type === POST_ESPECIAL_TYPE && in_array($post->ID, $ids_especiales)) {
unset($actions['trash']);
}
return $actions;
}, 10, 2);
// Mensaje de advertencia en los posts
add_filter('display_post_states', function($post_states, $post) use ($ids_especiales) {
if ($post->post_type === 'acerca' && in_array($post->ID, $ids_especiales)) {
$post_states['protegido'] = '🔒 No se puede borrar';
}
return $post_states;
}, 10, 2);
/** FIN *************POST "QUÉ ES LA CNT" */
// 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')) {
@ -93,11 +54,6 @@ class StarterSite extends Site {
}
});
// Handler AJAX para cargar contenido de páginas
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') {
@ -122,9 +78,8 @@ class StarterSite extends Site {
function load_assets() {
$version = 4;
// $version_for_app = $version;
$version_for_app = time();
// $version = 4;
$version = time();
wp_enqueue_style( 'yaro', get_template_directory_uri() . '/assets/fonts/yaro-font-family/stylesheet.css', [], $version, 'all');
wp_enqueue_style( 'twbs', get_template_directory_uri() . '/vendor/twbs/bootstrap/dist/css/bootstrap.min.css', [], $version, 'all');
wp_enqueue_style( 'twbsi', get_template_directory_uri() . '/vendor/twbs/bootstrap-icons/font/bootstrap-icons.min.css', [], $version, 'all');
@ -481,7 +436,7 @@ class StarterSite extends Site {
private function getSubpaginasServicios() {
$pathInfo = $this->whichPathIs();
// Si no encontramos una página válida, retornar vacío
if (!$pathInfo['found']) {
return [
@ -607,79 +562,6 @@ class StarterSite extends Site {
]) : [];
}
// Obtiene las subpaginas Acerca CNT
private function getSubpaginasAcercaCnt() {
$current_lang = pll_current_language(); // Detectar idioma actual
$page_slug = ($current_lang == 'eu') ? 'cnt-ri-buruz' : 'acerca-de-la-cnt';
$parent_page = get_page_by_path($page_slug);
if (!$parent_page) {
return [];
}
$args = array(
'post_type' => 'page',
'post_parent' => $parent_page->ID,
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1
);
return Timber::get_posts($args);
}
// Identifica el id de la Subpágina "Acerca de la cnt"
public function get_page_content_ajax() {
$page_id = intval($_POST['page_id']);
if (!$page_id) {
wp_send_json_error('ID de página no válido');
}
$page = Timber::get_post($page_id);
if (!$page) {
wp_send_json_error('Página no encontrada');
}
wp_send_json_success([
'title' => $page->title,
'content' => apply_filters('the_content', $page->content),
'url' => get_permalink($page_id) // Añade la URL de la página
]);
}
// Redirige a las subpaginas de "Acerca de la cnt"
public function redirect_subpaginas_acerca() {
if (!is_page()) {
return;
}
global $post;
// Obtener las páginas padre (español y euskera)
$parent_es = get_page_by_path('acerca-de-la-cnt');
$parent_eu = get_page_by_path('cnt-ri-buruz');
$parent_ids = array_filter([
$parent_es ? $parent_es->ID : null,
$parent_eu ? $parent_eu->ID : null
]);
// Si es una subpágina de "Acerca de la CNT"
if ($post->post_parent && in_array($post->post_parent, $parent_ids)) {
// Redirigir a la página padre con el ID de la subpágina
$parent_url = get_permalink($post->post_parent);
$redirect_url = add_query_arg('subpage', $post->ID, $parent_url);
wp_redirect($redirect_url, 301);
exit;
}
}
// *** Global variables ***
public function add_global_context($context) {
@ -691,10 +573,12 @@ class StarterSite extends Site {
$context['footer_2'] = get_field('footer_text_2', 'option');
//Otras páginas
$context['SubpaginasAcercaCnt'] = $this->getSubpaginasAcercaCnt();
$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

View File

@ -50,7 +50,7 @@
<!-- footer -->
{% block footer %}
<footer id="footer" class="container-fluid text-bg-dark mt-5">
<footer id="footer" class="container-fluid text-bg-dark mt-5 section-footer">
{% include 'partials/footer.twig' %}
</footer>
{{ function('wp_footer') }}