Limiter le nombre d’articles mis en avant

Si vous voulez qu’il y ait un nombre fixe de billets mis en avant sans avoir à modi­fier à chaque fois l’état des billets, ce code à placer dans le fichier functions.php de votre thème va auto­ma­ti­ser le proces­sus en ne conser­vant l’état mis en avant que pour un nombre fixé de billets.
Rempla­cez le -1 du code par -N ou N est le nombre choisi.

Source : http://​www​.geek​press​.fr/​w​o​r​d​p​r​e​s​s​/​a​s​t​u​c​e​/​l​i​m​i​t​e​r​-​a​r​t​i​c​l​e​-​s​t​i​c​k​y​-​p​o​s​t​s​-​1​3​69/

Code

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, -1 );
}

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: