-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage-academy.php
118 lines (106 loc) · 4.44 KB
/
page-academy.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Template Name: Academia
* Description: Plantilla para listar los cursos del Custom Post Type (CPT) "cursos" separados por la taxonomía "modalidad" (presencial y online).
*
* 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.
*
* Estructura de la página:
* 1. Cabecera dinámica mediante un pageheader reutilizable.
* 2. Contenido principal de la página.
* 3. Dos secciones separadas: Formación Presencial y Formación Online.
* 4. Bloques dinámicos cargados desde ACF.
*
* Personalización:
* - La función render_cursos_by_modalidad() maneja la lógica para listar cursos según la taxonomía.
*/
$bodyclass = 'page-cursos';
$cpt_slug = 'cursos'; // Custom Post Type: Cursos
$taxonomy = 'modalidad'; // Taxonomía: modalidad (presencial u online)
$terms = get_terms(['taxonomy' => $taxonomy, 'hide_empty' => true]); // Obtener términos de taxonomía
$fields = get_fields();
$content = get_the_content();
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']);
?>
<!-- Sección de Contenido Principal -->
<?php if (!empty($content)) : ?>
<div class="bg-light-subtle py-5">
<div class="container">
<?php echo $content; ?>
</div>
</div>
<?php endif; ?>
<!-- Listado de Cursos por Taxonomía -->
<section class="cpt-courses container my-5">
<?php
// Función para renderizar cursos por modalidad
function render_cursos_by_modalidad($taxonomy, $term, $cpt_slug, $section_title, $class_section) {
$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($class_section); ?>">
<h2 class="section-title heading-3 text-uppercase mb-4">
<?php echo esc_html($section_title); ?>
</h2>
<div class="row">
<?php
while ($query->have_posts()) : $query->the_post();
// Plantilla para cada curso
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
wp_reset_postdata();
else :
echo '<p class="text-center">No hay cursos disponibles en esta modalidad.</p>';
endif;
}
if (!empty($terms) && !is_wp_error($terms)) :
$total_terms = count($terms); // Número total de términos
$current_index = 0; // Inicializa contador
foreach ($terms as $term) :
$current_index++;
// Determinar la clase de sección
$section_class = 'cpt-section mb-5';
if ($current_index !== $total_terms) {
$section_class .= ' pb-5 border-bottom'; // Añadir clase excepto en el último término
}
// Renderizar cursos del término actual
render_cursos_by_modalidad($taxonomy, $term->slug, $cpt_slug, 'Formación ' . ucfirst($term->name), $section_class);
endforeach;
else :
echo '<p class="text-center">No hay cursos disponibles.</p>';
endif;
?>
</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(); ?>