WordPress: creare un Loop di soli post in evidenza (sticky)

WordPress: creare un Loop di soli post in evidenza (sticky)

I post in evidenza (sticky) vengono registrati da WordPress nell'opzione sticky_posts come array di ID. Possiamo sfruttare quest'opzione per reperire solo i post in evidenza.

Il codice รจ il seguente:


<?php
$sticky = get_option('sticky_posts'); // array di ID dei post
rsort( $sticky ); // ordine decrescente

$sticky = array_slice( $sticky, 0, 5); // solo i primi 6 post

$loop = new WP_Query( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );

if ($loop->have_posts()) :
    while ($loop->have_posts()) : $loop->the_post();
        the_title();
        the_excerpt();
    endwhile;
endif;

?>

Torna su