Initial commit
This commit is contained in:
48
page-programmes-de-recherche.php
Normal file
48
page-programmes-de-recherche.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
$context = Timber::context();
|
||||
$post = Timber::get_post();
|
||||
$context['post'] = $post;
|
||||
|
||||
$terms = get_terms( [ 'taxonomy' => 'programme_de_recherche', 'hide_empty' => false ] );
|
||||
|
||||
$sections = [
|
||||
'subventionne' => [ 'label' => 'Programmes subventionnés', 'items' => [] ],
|
||||
'autre' => [ 'label' => 'Autres programmes', 'items' => [] ],
|
||||
'ancien' => [ 'label' => 'Anciens programmes', 'items' => [] ],
|
||||
];
|
||||
|
||||
foreach ( $terms as $term ) {
|
||||
$type = get_term_meta( $term->term_id, 'type_de_programme', true );
|
||||
|
||||
$item = [
|
||||
'name' => $term->name,
|
||||
'description' => wpautop( $term->description ),
|
||||
'url' => get_term_link( $term ),
|
||||
'annee_fin' => (int) get_term_meta( $term->term_id, 'annee_fin', true ),
|
||||
];
|
||||
|
||||
if ( $type === 'Programme subventionné' ) {
|
||||
$sections['subventionne']['items'][] = $item;
|
||||
} elseif ( $type === 'Ancien programme' ) {
|
||||
$sections['ancien']['items'][] = $item;
|
||||
} else {
|
||||
// "Autre programme" or no type set
|
||||
$sections['autre']['items'][] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by annee_fin descending (most recent end year first); items without a year go last
|
||||
foreach ( $sections as &$section ) {
|
||||
usort( $section['items'], function( $a, $b ) {
|
||||
if ( $a['annee_fin'] === $b['annee_fin'] ) return strcmp( $a['name'], $b['name'] );
|
||||
if ( ! $a['annee_fin'] ) return 1;
|
||||
if ( ! $b['annee_fin'] ) return -1;
|
||||
return $b['annee_fin'] - $a['annee_fin'];
|
||||
} );
|
||||
}
|
||||
unset( $section );
|
||||
|
||||
$context['sections'] = array_values( $sections );
|
||||
$context['page_edit_link'] = current_user_can( 'edit_page', $post->ID ) ? get_edit_post_link( $post->ID ) : '';
|
||||
|
||||
Timber::render( 'page-programmes-de-recherche.twig', $context );
|
||||
Reference in New Issue
Block a user