Du hast mit „Sticky Posts“ etwas ganz besonders vor (zum Beispiel einen Slider auf der Startseite einrichten) und willst vermeiden, dass sie im Main Loop nochmal aufgelistet werden?
So bekommst Du Sticky Posts aus dem Main Loop raus.
function ppt_exclude_sticky_from_mainquery( $query ) {
if ( ! is_preview() && ! is_admin() && ! is_singular() ) {
$sticky = get_option( 'sticky_posts' );
$query->set( 'post__not_in', $sticky );
}
}
add_action( 'pre_get_posts' , 'ppt_exclude_sticky_from_mainquery' );
Nun kannst Du „Sticky Posts“ (beispielsweise) in Deinem Startseitentemplate mit einem Custom Query aufrufen, dort in eine Slideshow einbauen oder sonst nach Belieben „loopen“ und gestalten.
// check if any post ist sticky
$sticky = get_option('sticky_posts');
// prevents from displaying all other posts when "post__in" array is empty
if( $sticky ) :
$featured_args = array(
'post__in' => get_option( 'sticky_posts' ),
'post_status' => 'publish'
);
$featured = new WP_query( $featured_args );
if ( $featured->have_posts() ) {
while ( $featured->have_posts() ) {
$featured->the_post();
/// do sticky posts stuff here
}
// Reset the post data
wp_reset_postdata();
}
endif;
Schreibe einen Kommentar