-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-courses-presencial.php
96 lines (85 loc) · 3.79 KB
/
page-courses-presencial.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Template Name: Formación Presencial
* Description: Plantilla para listar solo los cursos de modalidad "presencial".
*
* Requisitos:
* - Debe existir un Custom Post Type (CPT) con slug 'cursos'.
* - La taxonomía asociada "modalidad" debe contener los términos 'presencial' y 'online'.
* - Se requiere el uso del template part 'template-parts/components/card-cpt' para renderizar cada curso.
* - Los campos flexibles ACF 'flexible_content' se cargarán al final de la página si están definidos.
*/
$cpt_slug = 'cursos'; // Custom Post Type: Cursos
$taxonomy = 'modalidad'; // Taxonomía: modalidad
$term_slug = 'presencial'; // Término específico para cursos presenciales
$fields = get_fields();
$page_title = get_the_title();
$section_title = !empty($fields['pageheader_title'])
? $fields['pageheader_title']
: 'Formación Presencial';
$section_title_class = 'section-title heading-2 mb-4 text-center';
$htag_section_title = 1; # H2
get_header(); ?>
<main class="main-content">
<?php
// Mostrar cabecera de la página con estilo "bg-image"
get_template_part('template-parts/pageheader', null, [
'pageheader_style' => 'bg-image',
'title' => $page_title,
]);
?>
<!-- Sección Cursos Presenciales -->
<section class="cpt-courses container my-5">
<?php
/**
* Función para renderizar cursos por taxonomía específica.
*
* @param string $taxonomy Taxonomía (ej: modalidad).
* @param string $term Slug del término (ej: online).
* @param string $cpt_slug Slug del Custom Post Type (ej: cursos).
* @param string $section_title Título de la sección.
* @param string $section_class Clase adicional para la sección.
*/
function render_courses($taxonomy, $term, $cpt_slug, $section_title, $section_class, $htag_section_title, $section_title_class) {
$query = new WP_Query([
'post_type' => $cpt_slug,
'posts_per_page' => -1,
'tax_query' => [[
'taxonomy' => $taxonomy,
'field' => 'slug',
'terms' => $term,
]],
]);
if ($query->have_posts()) : ?>
<div class="<?php echo esc_attr($section_class); ?>">
<?php echo tagTitle($htag_section_title, $section_title, $section_title_class, ''); ?>
<div class="row">
<?php
while ($query->have_posts()) : $query->the_post();
get_template_part('template-parts/components/card-cpt', null, [
'title' => get_the_title(),
'excerpt' => wp_trim_words(get_the_excerpt(), 20),
'image_url' => get_the_post_thumbnail_url(get_the_ID(), 'medium'),
'permalink' => get_permalink(),
'class-col' => 'col-md-6 col-lg-4 col-xl-3',
]);
endwhile;
?>
</div>
</div>
<?php
else :
echo '<p class="text-center">No hay cursos disponibles para esta modalidad.</p>';
endif;
wp_reset_postdata();
}
render_courses($taxonomy, $term_slug, $cpt_slug, $section_title, 'cpt-section my-5', $htag_section_title, $section_title_class);
?>
</section>
<?php
// Cargar bloques flexibles dinámicamente
require_once get_template_directory() . '/template-parts/load-flexible-blocks.php';
load_flexible_blocks($fields['flexible_content']);
?>
</main>
<?php get_footer(); ?>