get( 'Version' ) ); } endif; add_action( 'wp_enqueue_scripts', 'twentytwentyfive_enqueue_styles' ); // Registers custom block styles. if ( ! function_exists( 'twentytwentyfive_block_styles' ) ) : /** * Registers custom block styles. * * @since Twenty Twenty-Five 1.0 * * @return void */ function twentytwentyfive_block_styles() { register_block_style( 'core/list', array( 'name' => 'checkmark-list', 'label' => __( 'Checkmark', 'twentytwentyfive' ), 'inline_style' => ' ul.is-style-checkmark-list { list-style-type: "\2713"; } ul.is-style-checkmark-list li { padding-inline-start: 1ch; }', ) ); } endif; add_action( 'init', 'twentytwentyfive_block_styles' ); // Registers pattern categories. if ( ! function_exists( 'twentytwentyfive_pattern_categories' ) ) : /** * Registers pattern categories. * * @since Twenty Twenty-Five 1.0 * * @return void */ function twentytwentyfive_pattern_categories() { register_block_pattern_category( 'twentytwentyfive_page', array( 'label' => __( 'Pages', 'twentytwentyfive' ), 'description' => __( 'A collection of full page layouts.', 'twentytwentyfive' ), ) ); register_block_pattern_category( 'twentytwentyfive_post-format', array( 'label' => __( 'Post formats', 'twentytwentyfive' ), 'description' => __( 'A collection of post format patterns.', 'twentytwentyfive' ), ) ); } endif; add_action( 'init', 'twentytwentyfive_pattern_categories' ); // Registers block binding sources. if ( ! function_exists( 'twentytwentyfive_register_block_bindings' ) ) : /** * Registers the post format block binding source. * * @since Twenty Twenty-Five 1.0 * * @return void */ function twentytwentyfive_register_block_bindings() { register_block_bindings_source( 'twentytwentyfive/format', array( 'label' => _x( 'Post format name', 'Label for the block binding placeholder in the editor', 'twentytwentyfive' ), 'get_value_callback' => 'twentytwentyfive_format_binding', ) ); } endif; add_action( 'init', 'twentytwentyfive_register_block_bindings' ); // Registers block binding callback function for the post format name. if ( ! function_exists( 'twentytwentyfive_format_binding' ) ) : /** * Callback function for the post format name block binding source. * * @since Twenty Twenty-Five 1.0 * * @return string|void Post format name, or nothing if the format is 'standard'. */ function twentytwentyfive_format_binding() { $post_format_slug = get_post_format(); if ( $post_format_slug && 'standard' !== $post_format_slug ) { return get_post_format_string( $post_format_slug ); } } endif; // ===== TAXONOMIE "Sources" ===== function journal_register_taxonomy_sources() { $labels = array( 'name' => 'Sources', 'singular_name' => 'Source', 'search_items' => 'Rechercher des sources', 'all_items' => 'Toutes les sources', 'parent_item' => 'Source parente', 'parent_item_colon' => 'Source parente :', 'edit_item' => 'Modifier la source', 'update_item' => 'Mettre à jour la source', 'add_new_item' => 'Ajouter une nouvelle source', 'new_item_name' => 'Nom de la nouvelle source', 'menu_name' => 'Sources', ); $args = array( 'labels' => $labels, 'public' => true, 'hierarchical' => true, // parent/enfant 'show_ui' => true, 'show_admin_column' => true, 'show_in_rest' => true, 'rewrite' => array('slug' => 'sources'), ); register_taxonomy('sources', array('post'), $args); } add_action('init', 'journal_register_taxonomy_sources'); // ===== FONCTION POUR AFFICHER UN ARBRE DE TAXONOMIE ===== function journal_afficher_arbre_taxonomie($taxonomy, $title) { $terms = get_terms(array( 'taxonomy' => $taxonomy, 'hide_empty' => false, )); if (empty($terms) || is_wp_error($terms)) { return "

Aucun terme trouvé pour : " . esc_html($taxonomy) . "

"; } // Hiérarchie parent -> enfants $hierarchie = array(); foreach ($terms as $term) { $hierarchie[$term->parent][] = $term; } $selected = array(); if (isset($_GET['tax_query'][$taxonomy]) && is_array($_GET['tax_query'][$taxonomy])) { $selected = array_map('intval', $_GET['tax_query'][$taxonomy]); } $build_tree = function($parent_id) use (&$build_tree, $hierarchie, $selected, $taxonomy) { if (!isset($hierarchie[$parent_id])) return ''; $html = ''; return $html; }; return '

'.esc_html($title).'

'.$build_tree(0); } // ===== SHORTCODE BLOG FILTRABLE ===== function journal_shortcode_blog_filtrable_relevanssi() { $search_term = isset($_GET['bfrr_s']) ? sanitize_text_field($_GET['bfrr_s']) : ''; $tax_query = array(); if (isset($_GET['tax_query']) && is_array($_GET['tax_query'])) { foreach ($_GET['tax_query'] as $taxonomy => $terms) { $terms = array_filter(array_map('intval', (array)$terms)); if (!empty($terms)) { $tax_query[] = array( 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $terms, 'operator' => 'IN', ); } } } if (count($tax_query) > 1) { $tax_query = array_merge(array('relation' => 'AND'), $tax_query); } ob_start(); // FORMULAIRE $page_obj = get_post(); // page actuelle $form_action = get_permalink($page_obj->ID); $form_action = strtok($form_action, '?'); // enlever query string echo '
'; echo '

'; echo journal_afficher_arbre_taxonomie('category', 'Catégories'); echo journal_afficher_arbre_taxonomie('sources', 'Sources'); echo '

'; echo '
'; // REQUÊTE FILTRÉE $paged = max(1, get_query_var('paged') ? get_query_var('paged') : (isset($_GET['paged']) ? intval($_GET['paged']) : 1)); $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'ignore_sticky_posts' => true, 's' => $search_term, 'paged' => $paged, 'posts_per_page' => 10, ); if (!empty($tax_query)) $args['tax_query'] = $tax_query; $query = new WP_Query($args); echo '
'; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); echo '
'; echo '

'.esc_html(get_the_title()).'

'; echo '

Publié le '.esc_html(get_the_date()).'

'; echo '
'.wp_kses_post(wp_trim_words(get_the_excerpt(), 30, '...')).'
'; echo '
'; } echo paginate_links(array( 'total' => $query->max_num_pages, 'current' => $paged, )); } else { echo '

Aucun article trouvé.

'; } echo '
'; wp_reset_postdata(); ?> 'post', 'post_status' => 'publish', 'posts_per_page' => 1, ]; $query = new WP_Query( $args ); if ( ! $query->have_posts() ) { return '

Aucun article trouvé.

'; } ob_start(); while ( $query->have_posts() ) { $query->the_post(); $post_id = get_the_ID(); $permalink = get_permalink(); echo '
'; // Titre cliquable echo '

' . esc_html( get_the_title() ) . '

'; // Date echo '

Publié le ' . esc_html( get_the_date() ) . '

'; // Catégories $cats_list = get_the_category_list( ', ' ); if ( $cats_list ) { echo '

Catégories : ' . wp_kses_post( $cats_list ) . '

'; } // Sources (taxonomie personnalisée) $sources = get_the_terms( $post_id, 'sources' ); if ( $sources && ! is_wp_error( $sources ) ) { $sources_names = wp_list_pluck( $sources, 'name' ); echo '

Sources : ' . esc_html( implode( ', ', $sources_names ) ) . '

'; } // Étiquettes $tags_list = get_the_tag_list( '', ', ' ); if ( $tags_list ) { echo '

Étiquettes : ' . wp_kses_post( $tags_list ) . '

'; } // 🔹 EXTRAI T (et non plus le contenu complet) echo '
'; echo wp_kses_post( wp_trim_words( get_the_excerpt(), 55, '...' ) ); echo '
'; // 🔹 Bouton "Lire l'article complet" echo '

'; echo 'Lire l’article complet'; echo '

'; echo '
'; } wp_reset_postdata(); return ob_get_clean(); } } add_shortcode( 'dernier_article', 'bfrr_dernier_article_shortcode' ); // ===== SHORTCODE [derniers_articles nb="3"] ===== // Affiche N derniers articles avec image mise en avant + métas + extrait + bouton + commentaires if ( ! function_exists( 'bfrr_derniers_articles_shortcode' ) ) { function bfrr_derniers_articles_shortcode( $atts ) { // Attributs : nb = nombre d'articles à afficher (défaut = 3) $atts = shortcode_atts( [ 'nb' => 3, ], $atts, 'derniers_articles' ); $nb = max( 1, intval( $atts['nb'] ) ); $args = [ 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $nb, ]; $query = new WP_Query( $args ); if ( ! $query->have_posts() ) { return '

Aucun article trouvé.

'; } ob_start(); echo '
'; while ( $query->have_posts() ) { $query->the_post(); $post_id = get_the_ID(); $permalink = get_permalink(); echo '
'; // Bloc image mise en avant (optionnel) if ( has_post_thumbnail( $post_id ) ) { echo ''; } echo '
'; // Titre cliquable echo '

' . esc_html( get_the_title() ) . '

'; // Date echo '

Publié le ' . esc_html( get_the_date() ) . '

'; // Catégories $cats_list = get_the_category_list( ', ' ); if ( $cats_list ) { echo '

Catégories : ' . wp_kses_post( $cats_list ) . '

'; } // Sources (taxonomie personnalisée) $sources = get_the_terms( $post_id, 'sources' ); if ( $sources && ! is_wp_error( $sources ) ) { $sources_names = wp_list_pluck( $sources, 'name' ); echo '

Sources : ' . esc_html( implode( ', ', $sources_names ) ) . '

'; } // Étiquettes $tags_list = get_the_tag_list( '', ', ' ); if ( $tags_list ) { echo '

Étiquettes : ' . wp_kses_post( $tags_list ) . '

'; } // Extrait echo '
'; echo wp_kses_post( wp_trim_words( get_the_excerpt(), 55, '...' ) ); echo '
'; // Bouton vers l'article complet echo '

'; echo 'Lire l’article complet'; echo '

'; // 🔹 Zone de commentaires sur la page d'accueil (ou la page du shortcode) echo '
'; echo '

Laisser un commentaire sur cet article

'; $comment_args = [ 'title_reply' => '', 'label_submit' => 'Envoyer le commentaire', 'comment_field' => '

', ]; // Les commentaires seront liés à la page courante (la page où se trouve le shortcode) comment_form( $comment_args ); echo '
'; // .bfrr-da-comments-block echo '
'; // .bfrr-da-content echo '
'; } echo '
'; wp_reset_postdata(); return ob_get_clean(); } } add_shortcode( 'derniers_articles', 'bfrr_derniers_articles_shortcode' );