ADD routes noticias

This commit is contained in:
2025-10-15 11:23:50 +00:00
parent 5478f15b7f
commit 096b6c90a4
5 changed files with 45 additions and 9 deletions

19
archive-noticias.php Normal file
View File

@ -0,0 +1,19 @@
<?php
/**
* Category 'noticias'
* Temporal. De momento no pasan por aquí.
*/
global $params;
$context = Timber::context();
// var_dump(get_cat_ID('Noticias'));
$category = get_category_by_slug('noticias');
$query = array(
'post_type' => '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);

View File

@ -13,7 +13,7 @@ namespace App;
use Timber\Timber; use Timber\Timber;
$templates = [ 'templates/archive.twig', 'templates/index.twig' ]; $templates = [ 'templates/archive.twig', 'templates/index.twig' ];
error_log('✅ estamos en archive'); error_log('✅ estamos en archive.php');
$title = 'Archive'; $title = 'Archive';
if ( is_day() ) { if ( is_day() ) {

View File

@ -39,7 +39,8 @@
"timber/timber": "^2.1", "timber/timber": "^2.1",
"illuminate/collections": "^12.20", "illuminate/collections": "^12.20",
"twbs/bootstrap": "^5.3", "twbs/bootstrap": "^5.3",
"twbs/bootstrap-icons": "^1.13" "twbs/bootstrap-icons": "^1.13",
"upstatement/routes": "^0.9.2"
}, },
"require-dev": { "require-dev": {
"automattic/wordbless": "^0.4.2", "automattic/wordbless": "^0.4.2",

View File

@ -9,10 +9,26 @@
namespace App; namespace App;
use Routes;
use Timber\Timber; use Timber\Timber;
// Load Composer dependencies. // Load Composer dependencies.
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
Timber::init(); Timber::init();
$site = new StarterSite(); $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);
});
}

View File

@ -44,12 +44,12 @@ if ($parent && ($parent->post_name === 'contactos' || $parent->post_name === 'ko
//error_log('✅ (page.php) Página "Industria": ' . $parent->post_name); //error_log('✅ (page.php) Página "Industria": ' . $parent->post_name);
Timber::render('templates/single-industria.twig', $context); Timber::render('templates/single-industria.twig', $context);
} elseif ( $slug_actual === 'noticias' || $slug_actual === 'berriak') { } elseif ( $slug_actual === 'noticias' || $slug_actual === 'berriak') {
$context['posts_noticias'] = Timber::get_posts(array( // $context['posts_noticias'] = Timber::get_posts(array(
'post_type' => 'post', // 'post_type' => 'post',
'cat' => get_cat_ID('noticias'), // Obtiene los posts de la categoría "noticias" // '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'])); error_log('🔴 (page.php) Página noticias - ERROR');
Timber::render('templates/page-noticias.twig', $context); // Timber::render('templates/page-noticias.twig', $context);
} else { } else {
error_log('✅ (page.php) Página: ' . $parent->post_name); error_log('✅ (page.php) Página: ' . $parent->post_name);
Timber::render(array('templates/page-' . $timber_post->post_name . '.twig'), $context); Timber::render(array('templates/page-' . $timber_post->post_name . '.twig'), $context);