From 096b6c90a46e9f9b57fe2f876f15bedcc8b4a0c4 Mon Sep 17 00:00:00 2001 From: gustavo Date: Wed, 15 Oct 2025 11:23:50 +0000 Subject: [PATCH] ADD routes noticias --- archive-noticias.php | 19 +++++++++++++++++++ archive.php | 2 +- composer.json | 3 ++- functions.php | 18 +++++++++++++++++- page.php | 12 ++++++------ 5 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 archive-noticias.php diff --git a/archive-noticias.php b/archive-noticias.php new file mode 100644 index 0000000..2eca600 --- /dev/null +++ b/archive-noticias.php @@ -0,0 +1,19 @@ + 'post', + 'cat' => $category ? $category->term_id : 201, + 'paged' => isset($params['paged']) ? $params['paged'] : 1, + 'posts_per_page' => get_option('posts_per_page') // Usa la configuración de WordPress + ); +$context['posts_noticias'] = Timber::get_posts($query); +error_log('✅ category-noticias.php - Posts: ' . count($context['posts_noticias'])); + +Timber::render('templates/page-noticias.twig', $context); \ No newline at end of file diff --git a/archive.php b/archive.php index 6ec219a..42bbbef 100644 --- a/archive.php +++ b/archive.php @@ -13,7 +13,7 @@ namespace App; use Timber\Timber; $templates = [ 'templates/archive.twig', 'templates/index.twig' ]; -error_log('✅ estamos en archive'); +error_log('✅ estamos en archive.php'); $title = 'Archive'; if ( is_day() ) { diff --git a/composer.json b/composer.json index d840b9d..f5edb98 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "timber/timber": "^2.1", "illuminate/collections": "^12.20", "twbs/bootstrap": "^5.3", - "twbs/bootstrap-icons": "^1.13" + "twbs/bootstrap-icons": "^1.13", + "upstatement/routes": "^0.9.2" }, "require-dev": { "automattic/wordbless": "^0.4.2", diff --git a/functions.php b/functions.php index e4cd169..7d0176f 100644 --- a/functions.php +++ b/functions.php @@ -9,10 +9,26 @@ namespace App; +use Routes; use Timber\Timber; // Load Composer dependencies. require_once __DIR__ . '/vendor/autoload.php'; Timber::init(); - $site = new StarterSite(); + +// Ruta para la página principal 'noticias' +foreach(['/es/noticias','/eu/berriak'] as $route) { + Routes::map($route, function($params){ + $query = false; + Routes::load('archive-noticias.php', $params, $query, 200); + }); +} + +// Ruta para las páginas de paginación 'noticias' +foreach(['/es/noticias/page/:paged','/eu/berriak/page/:paged'] as $route) { + Routes::map($route, function($params){ + $query = false; + Routes::load('archive-noticias.php', $params, $query, 200); + }); +} \ No newline at end of file diff --git a/page.php b/page.php index 3ccc547..3e93012 100644 --- a/page.php +++ b/page.php @@ -44,12 +44,12 @@ if ($parent && ($parent->post_name === 'contactos' || $parent->post_name === 'ko //error_log('✅ (page.php) Página "Industria": ' . $parent->post_name); Timber::render('templates/single-industria.twig', $context); } elseif ( $slug_actual === 'noticias' || $slug_actual === 'berriak') { - $context['posts_noticias'] = Timber::get_posts(array( - 'post_type' => 'post', - 'cat' => get_cat_ID('noticias'), // Obtiene los posts de la categoría "noticias" - )); - //error_log('✅ (page.php) Página noticias - Posts: ' . count($context['posts_noticias'])); - Timber::render('templates/page-noticias.twig', $context); + // $context['posts_noticias'] = Timber::get_posts(array( + // 'post_type' => 'post', + // 'cat' => get_cat_ID('noticias'), // Obtiene los posts de la categoría "noticias" + // )); + error_log('🔴 (page.php) Página noticias - ERROR'); + // Timber::render('templates/page-noticias.twig', $context); } else { error_log('✅ (page.php) Página: ' . $parent->post_name); Timber::render(array('templates/page-' . $timber_post->post_name . '.twig'), $context);