ADD new page acerca de la cnt
This commit is contained in:
@@ -85,6 +85,18 @@ class StarterSite extends Site {
|
|||||||
}, 10, 2);
|
}, 10, 2);
|
||||||
/** FIN *************POST "QUÉ ES LA CNT" */
|
/** FIN *************POST "QUÉ ES LA CNT" */
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
$query->set('lang', '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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']);
|
||||||
|
|
||||||
// *** SOLO USAR UNA VEZ PARA LIMPIAR. NO FUNCIONABA LA PAGINACIÓN DE SEARCH.
|
// *** SOLO USAR UNA VEZ PARA LIMPIAR. NO FUNCIONABA LA PAGINACIÓN DE SEARCH.
|
||||||
// add_action('init', function() {
|
// add_action('init', function() {
|
||||||
// add_rewrite_rule(
|
// add_rewrite_rule(
|
||||||
@@ -309,7 +321,7 @@ class StarterSite extends Site {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $polylang_data;
|
return $polylang_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,15 +361,16 @@ class StarterSite extends Site {
|
|||||||
return $logos;
|
return $logos;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPaginasAcerca() {
|
// Recoge los posts del Post Type (ACF) Acerca
|
||||||
return Timber::get_posts([
|
// private function getPaginasAcerca() {
|
||||||
'post_type' => 'acerca',
|
// return Timber::get_posts([
|
||||||
'post_status' => 'publish',
|
// 'post_type' => 'acerca',
|
||||||
'orderby' => 'menu_order',
|
// 'post_status' => 'publish',
|
||||||
'order' => 'ASC',
|
// 'orderby' => 'menu_order',
|
||||||
'posts_per_page' => -1,
|
// 'order' => 'ASC',
|
||||||
]);
|
// 'posts_per_page' => -1,
|
||||||
}
|
// ]);
|
||||||
|
// }
|
||||||
|
|
||||||
private function getDocumentos() {
|
private function getDocumentos() {
|
||||||
|
|
||||||
@@ -371,7 +384,7 @@ class StarterSite extends Site {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$posts = Timber::get_posts($args);
|
$posts = Timber::get_posts($args);
|
||||||
//error_log('✅ Número de posts "Documentos" encontrados: ' . count($posts));
|
error_log('✅ Número de posts "Documentos" encontrados: ' . count($posts));
|
||||||
|
|
||||||
$documentos = [];
|
$documentos = [];
|
||||||
|
|
||||||
@@ -628,7 +641,50 @@ class StarterSite extends Site {
|
|||||||
]) : [];
|
]) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Global variables
|
// 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)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// *** Global variables ***
|
||||||
public function add_global_context($context) {
|
public function add_global_context($context) {
|
||||||
|
|
||||||
// GLobales
|
// GLobales
|
||||||
@@ -639,8 +695,8 @@ class StarterSite extends Site {
|
|||||||
$context['footer_2'] = get_field('footer_text_2', 'option');
|
$context['footer_2'] = get_field('footer_text_2', 'option');
|
||||||
|
|
||||||
//Otras páginas
|
//Otras páginas
|
||||||
//$context['videos'] = $this->getVideos();
|
$context['SubpaginasAcercaCnt'] = $this->getSubpaginasAcercaCnt();
|
||||||
$context['paginas_acerca'] = $this->getPaginasAcerca();
|
//$context['paginas_acerca'] = $this->getPaginasAcerca();
|
||||||
$context['documentos'] = $this->getDocumentos();
|
$context['documentos'] = $this->getDocumentos();
|
||||||
$context['enlaces'] = $this->getEnlaces();
|
$context['enlaces'] = $this->getEnlaces();
|
||||||
$context['contacto_info'] = $this->getContactoFields();
|
$context['contacto_info'] = $this->getContactoFields();
|
||||||
|
|||||||
109
views/templates/page-acerca-de-la-cnt.twig
Normal file
109
views/templates/page-acerca-de-la-cnt.twig
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
{% extends 'layouts/base.twig' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p class="mb-5 position-relative fs-4 fw-bold sp-module-title">{{ post.title }}</p>
|
||||||
|
|
||||||
|
<div class="container mt-4">
|
||||||
|
<div class="row">
|
||||||
|
<!-- Columna izquierda: títulos -->
|
||||||
|
<div class="col-md-4 border-end">
|
||||||
|
<ul id="post-list" class="list-group">
|
||||||
|
{% for pagina in SubpaginasAcercaCnt %}
|
||||||
|
<li class="list-group-item {% if loop.first %}active-acerca{% endif %}" data-page-id="{{ pagina.id }}">
|
||||||
|
<a href="#"
|
||||||
|
data-page-id="{{ pagina.id }}"
|
||||||
|
class="text-decoration-none d-block w-100 {% if loop.first %}text-white{% else %}text-black{% endif %}">
|
||||||
|
{{ pagina.title }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Columna derecha: contenido del post -->
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div id="content-area">
|
||||||
|
{% if SubpaginasAcercaCnt|length > 0 %}
|
||||||
|
{% set primera = SubpaginasAcercaCnt|first %}
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="card-title">{{ primera.title }}</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body" style="padding-bottom: 60px;">
|
||||||
|
<div class="card-text">
|
||||||
|
{{ primera.content }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const postList = document.getElementById('post-list');
|
||||||
|
const contentArea = document.getElementById('content-area');
|
||||||
|
|
||||||
|
postList.addEventListener('click', function(e) {
|
||||||
|
const link = e.target.closest('a');
|
||||||
|
if (!link) return;
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const pageId = link.getAttribute('data-page-id');
|
||||||
|
|
||||||
|
// Remover clase active de todos
|
||||||
|
postList.querySelectorAll('.list-group-item').forEach(item => {
|
||||||
|
item.classList.remove('active-acerca');
|
||||||
|
const a = item.querySelector('a');
|
||||||
|
if (a) {
|
||||||
|
a.classList.remove('text-white');
|
||||||
|
a.classList.add('text-black');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Añadir clase active al clickeado
|
||||||
|
const listItem = link.closest('.list-group-item');
|
||||||
|
listItem.classList.add('active-acerca');
|
||||||
|
link.classList.add('text-white');
|
||||||
|
link.classList.remove('text-black');
|
||||||
|
|
||||||
|
// Mostrar loader
|
||||||
|
contentArea.innerHTML = '<div class="text-center p-5"><div class="spinner-border" role="status"><span class="visually-hidden">Cargando...</span></div></div>';
|
||||||
|
|
||||||
|
// Cargar contenido via AJAX
|
||||||
|
fetch('{{ site.url }}/wp-admin/admin-ajax.php', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
body: 'action=get_page_content&page_id=' + pageId
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
contentArea.innerHTML = `
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header">
|
||||||
|
<h5 class="card-title">${data.data.title}</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body" style="padding-bottom: 60px;">
|
||||||
|
<div class="card-text">
|
||||||
|
${data.data.content}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
contentArea.innerHTML = '<div class="alert alert-danger">Error al cargar el contenido</div>';
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -1 +1 @@
|
|||||||
{% extends 'templates/single-acerca.twig' %}
|
{% extends 'templates/page-acerca-de-la-cnt.twig' %}
|
||||||
|
|||||||
Reference in New Issue
Block a user