ADD redirect acerca de la cnt
This commit is contained in:
@ -96,7 +96,8 @@ 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']);
|
||||
|
||||
// *** SOLO USAR UNA VEZ PARA LIMPIAR. NO FUNCIONABA LA PAGINACIÓN DE SEARCH.
|
||||
// add_action('init', function() {
|
||||
// add_rewrite_rule(
|
||||
@ -384,7 +385,7 @@ class StarterSite extends Site {
|
||||
]);
|
||||
|
||||
$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 = [];
|
||||
|
||||
@ -664,7 +665,7 @@ class StarterSite extends Site {
|
||||
|
||||
}
|
||||
|
||||
// Identifica el id de la Subpágina Acerca de la cnt.
|
||||
// Identifica el id de la Subpágina "Acerca de la cnt"
|
||||
public function get_page_content_ajax() {
|
||||
$page_id = intval($_POST['page_id']);
|
||||
|
||||
@ -680,10 +681,40 @@ class StarterSite extends Site {
|
||||
|
||||
wp_send_json_success([
|
||||
'title' => $page->title,
|
||||
'content' => apply_filters('the_content', $page->content)
|
||||
'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) {
|
||||
|
||||
|
||||
@ -42,10 +42,91 @@
|
||||
</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>
|
||||
// `;
|
||||
|
||||
// // Actualizar URL en el navegador
|
||||
// if (data.data.url) {
|
||||
// history.pushState({pageId: pageId}, data.data.title, data.data.url);
|
||||
// document.title = data.data.title + ' - {{ site.name }}';
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .catch(error => {
|
||||
// contentArea.innerHTML = '<div class="alert alert-danger">Error al cargar el contenido</div>';
|
||||
// console.error('Error:', error);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const postList = document.getElementById('post-list');
|
||||
const contentArea = document.getElementById('content-area');
|
||||
|
||||
// Detectar si hay una subpágina en la URL
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const subpageId = urlParams.get('subpage');
|
||||
|
||||
if (subpageId) {
|
||||
// Buscar y hacer click en la subpágina correspondiente
|
||||
const link = document.querySelector(`a[data-page-id="${subpageId}"]`);
|
||||
if (link) {
|
||||
link.click();
|
||||
}
|
||||
}
|
||||
|
||||
postList.addEventListener('click', function(e) {
|
||||
const link = e.target.closest('a');
|
||||
if (!link) return;
|
||||
@ -96,6 +177,14 @@
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Actualizar URL en el navegador
|
||||
if (data.data.url) {
|
||||
const parentUrl = window.location.pathname;
|
||||
const newUrl = parentUrl + '?subpage=' + pageId;
|
||||
history.pushState({pageId: pageId}, data.data.title, newUrl);
|
||||
document.title = data.data.title + ' - {{ site.name }}';
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@ -104,6 +193,18 @@
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Manejar botones atrás/adelante del navegador
|
||||
window.addEventListener('popstate', function(e) {
|
||||
if (e.state && e.state.pageId) {
|
||||
// Simular click en el elemento correspondiente
|
||||
const link = document.querySelector(`a[data-page-id="${e.state.pageId}"]`);
|
||||
if (link) {
|
||||
link.click();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user