Files
thalim-theme/page-le-laboratoire.php
2026-05-12 23:33:46 +02:00

111 lines
4.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$context = Timber::context();
$post = Timber::get_post();
$context['post'] = $post;
$page_id = $post->ID;
// ── Liens (internal page links) ──────────────────────────────
$lien_ids = get_post_meta( $page_id, 'liens', false );
$liens = [];
foreach ( $lien_ids as $lid ) {
$lid = intval( $lid );
if ( ! $lid ) continue;
$liens[] = [
'title' => get_the_title( $lid ),
'url' => get_permalink( $lid ),
];
}
$context['liens'] = $liens;
$labo_lang = thalim_current_language();
// ── Images (two side-by-side slots) ──────────────────────────
$images = [];
foreach ( [ 'image_labo_1', 'image_labo_2' ] as $field ) {
$img_id = intval( get_post_meta( $page_id, $field, true ) );
if ( ! $img_id ) continue;
$src = wp_get_attachment_image_url( $img_id, 'large' );
if ( ! $src ) continue;
$images[] = [
'url' => $src,
'alt' => get_post_meta( $img_id, '_wp_attachment_image_alt', true ) ?: '',
'title' => thalim_bilingual( get_the_title( $img_id ), $labo_lang ),
];
}
$context['images'] = $images;
// ── Axes thématiques grouped by period ───────────────────────
$terms = get_terms( [ 'taxonomy' => 'axe_thematique', 'hide_empty' => false ] );
$axes_map = [];
$label_prefix = $labo_lang === 'en' ? 'Research areas ' : 'Axes thématiques ';
$label_passes = $labo_lang === 'en' ? 'Past research areas' : 'Axes thématiques antérieurs';
foreach ( $terms as $term ) {
$debut = trim( get_term_meta( $term->term_id, 'annee_debut', true ) );
$fin = trim( get_term_meta( $term->term_id, 'annee_fin', true ) );
if ( $debut && $fin ) {
$key = $debut . '-' . $fin;
$label = $label_prefix . $debut . ' ' . $fin;
} else {
$key = 'passes';
$label = $label_passes;
}
if ( ! isset( $axes_map[ $key ] ) ) {
$axes_map[ $key ] = [
'label' => $label,
'debut' => intval( $debut ),
'terms' => [],
];
}
$ordre = trim( get_term_meta( $term->term_id, 'ordre_daffichage', true ) );
$axes_map[ $key ]['terms'][] = [
'name' => $term->name,
'url' => get_term_link( $term ),
'ordre' => $ordre !== '' ? intval( $ordre ) : null,
];
}
// Sort: newest first by annee_debut, 'passes' always last (debut === 0)
uasort( $axes_map, function ( $a, $b ) {
if ( $a['debut'] === 0 ) return 1;
if ( $b['debut'] === 0 ) return -1;
return $b['debut'] - $a['debut'];
} );
// Within each group: numbered items first (ascending), then unnumbered alphabetically
foreach ( $axes_map as &$group ) {
usort( $group['terms'], function ( $a, $b ) {
$a_has = $a['ordre'] !== null;
$b_has = $b['ordre'] !== null;
if ( $a_has && $b_has ) return $a['ordre'] - $b['ordre'];
if ( $a_has ) return -1;
if ( $b_has ) return 1;
return strcmp( $a['name'], $b['name'] );
} );
}
unset( $group );
$context['axes_groups'] = array_values( $axes_map );
// ── Body (English override) ──────────────────────────────────
$context['body_en'] = apply_filters( 'the_content', get_post_meta( $page_id, 'body_en', true ) ?: '' );
// ── WYSIWYG fields ────────────────────────────────────────────
$context['partenaires_internationaux'] = wpautop( ( $labo_lang === 'en' && get_post_meta( $page_id, 'partenaires_internationaux_en', true ) )
? get_post_meta( $page_id, 'partenaires_internationaux_en', true )
: ( get_post_meta( $page_id, 'partenaires_internationaux', true ) ?: '' ) );
$context['partenaires_nationaux'] = wpautop( ( $labo_lang === 'en' && get_post_meta( $page_id, 'partenaires_nationaux_en', true ) )
? get_post_meta( $page_id, 'partenaires_nationaux_en', true )
: ( get_post_meta( $page_id, 'partenaires_nationaux', true ) ?: '' ) );
$context['bibliotheques'] = wpautop( ( $labo_lang === 'en' && get_post_meta( $page_id, 'bibliotheques_en', true ) )
? get_post_meta( $page_id, 'bibliotheques_en', true )
: ( get_post_meta( $page_id, 'bibliotheques', true ) ?: '' ) );
// ── Edit link ─────────────────────────────────────────────────
$context['page_edit_link'] = current_user_can( 'edit_page', $page_id ) ? get_edit_post_link( $page_id ) : '';
Timber::render( 'page-le-laboratoire.twig', $context );