Fare un post appiccicoso il primo post nel loop - WordPress
Domanda
Vorrei ottenere aiuto con un problema che sto avendo con la funzione dei post appiccicosi di WordPress.
Non riesco a capire come far rimanere il bastoncino all'inizio del ciclo. Ho un ciclo simile al suo:
<?php query_posts('cat=10&posts_per_page=3');?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
E vorrei che funzionasse così:
- Post appiccicoso
- Post ordinario
- Post ordinario
Invece per:
- Post ordinario
- Post appiccicoso
- Post ordinario
Grazie per l'aiuto!
Soluzione
La mia soluzione qui http://codex.wordpress.org/class_reference/wp_query
Ho fatto due domande, in questo caso forse non sto usando la paginazione questo può aiutare
$sticky = get_option( 'sticky_posts' );
$args_nonsticky = array(
'showposts' => -1,
'post__not_in' => $sticky
);
$args_sticky = array(
'posts_per_page' => -1,
'post__in' => $sticky
);
$the_query_sticky = new WP_Query($args_sticky);
$the_query_nonsticky = new WP_Query($args_nonsticky);
if(!$the_query_sticky->have_posts() && !$the_query_nonsticky->have_posts()){
//echo '<h1>NO POSTS FOUND</h1>';
}else{
if ( $sticky[0] ) {
while ($the_query_sticky->have_posts()) : $the_query_sticky->the_post();
//sticky if so...
endwhile;
}
while ($the_query_nonsticky->have_posts()) : $the_query_nonsticky->the_post();
// non sticky
endwhile;
}
Altri suggerimenti
L'ho provato sul mio sito demo. E l'ordine predefinito dovrebbe essere: - Sticky - Ordinary - Ordinary L'ordine predefinito non è - Ordinario - Sticky - Ordinario
Consiglio di provarlo con altri temi, come Ventyevers. Da lì è probabilmente un controllo di debug di base questo:http://codex.wordpress.org/sticky_posts