Afficher un nombre fixe d’articles mis en avant

Si vous ne voulez affi­cher qu’un nombre précis d’articles mis en avant sans à avoir à modi­fier à chaque fois l’état de publi­ca­tion de tous ces articles, ce code à insé­rer dans le fichier functions.php de votre thème va faire en sorte qu’à chaque nouveau article mis en avant, le plus vieux ayant cet état perde l’état « mis en avant », ce qui permet d’avoir un nombre fixe d’articles en avant sans modi­fi­ca­tions supplémentaires.

Code

//3 derniers sticky conservés
    add_filter( 'pre_update_option_sticky_posts', 'gkp_pre_update_option_sticky_posts' );
    function gkp_pre_update_option_sticky_posts( $posts ) {
        return array_slice( $posts, -3 );
    }

If you have found a spel­ling error, please, noti­fy us by selec­ting that text and pres­sing Ctrl+Enter.

Ce site embarque des cookies pour vous offrir la meilleur expérience possible

Spelling error report

The following text will be sent to our editors: