(string) self::DEFAULT_POSTS, 'titre' => __( 'Derniers articles', 'agentsia-agents' ), 'categorie' => '', 'auteur' => '', ], (array) $atts, self::SHORTCODE ); $count = absint( $atts['nombre'] ); $count = $count > 0 ? min( $count, self::MAX_POSTS ) : self::DEFAULT_POSTS; $post_id = self::current_post_id(); $category = trim( (string) $atts['categorie'] ); $author = trim( (string) $atts['auteur'] ); $args = [ 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $count, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'update_post_term_cache' => false, ]; if ( $post_id > 0 ) { $args['post__not_in'] = [ $post_id ]; } if ( $category === '' && $author === '' ) { // Par défaut : l'auteur relié à la page (page de membre réglée depuis Agentsia), sinon la catégorie // qui porte le slug de la page affichée. $post = $post_id > 0 ? get_post( $post_id ) : null; $linked = $post ? (int) get_post_meta( $post->ID, Site_Members::META_PAGE_AUTHOR, true ) : 0; $linked = $linked > 0 && get_userdata( $linked ) instanceof \WP_User ? $linked : 0; $term = $linked === 0 && $post && $post->post_name !== '' ? get_term_by( 'slug', $post->post_name, 'category' ) : false; if ( $linked > 0 ) { $args['author'] = $linked; } elseif ( ! $term instanceof \WP_Term ) { return self::editor_hint( $post_id, $post /* translators: %s: slug of the page. */ ? sprintf( __( 'Derniers articles : aucune catégorie d\'articles n\'a le slug de cette page (« %s »). Crée-la, ou choisis une catégorie ou un auteur dans les réglages du bloc.', 'agentsia-agents' ), $post->post_name ) : __( 'Derniers articles : choisis une catégorie ou un auteur dans les réglages du bloc.', 'agentsia-agents' ) ); } else { $args['cat'] = (int) $term->term_id; } } else { if ( $category !== '' ) { $term = self::category( $category ); if ( ! $term ) { /* translators: %s: category given in the settings. */ return self::editor_hint( $post_id, sprintf( __( 'Derniers articles : catégorie « %s » introuvable.', 'agentsia-agents' ), $category ) ); } $args['cat'] = (int) $term->term_id; } if ( $author !== '' ) { $user = self::author( $author ); if ( ! $user ) { /* translators: %s: author given in the settings. */ return self::editor_hint( $post_id, sprintf( __( 'Derniers articles : auteur « %s » introuvable.', 'agentsia-agents' ), $author ) ); } $args['author'] = (int) $user->ID; } } $query = new \WP_Query( $args ); if ( empty( $query->posts ) ) { return self::editor_hint( $post_id, __( 'Derniers articles : aucun article publié pour le moment.', 'agentsia-agents' ) ); } $items = ''; foreach ( $query->posts as $article ) { $excerpt = self::excerpt_of( $article ); $items .= sprintf( '
' . esc_html( $excerpt ) . '
' : '' ); } $title = trim( (string) $atts['titre'] ); return '' . esc_html( $message ) . '
'; } }