在循环中发布第一篇文章的粘性帖子 - WordPress

Lin*_*son 1 wordpress sticky

我想得到一个与WordPress粘贴帖子功能有关的问题的帮助.

我无法弄清楚如何使棍子贴到循环的开头.我有一个类似于他的循环:

<?php query_posts('cat=10&posts_per_page=3');?>  
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?> 
Run Code Online (Sandbox Code Playgroud)

我希望它能像这样工作:

  • 粘贴的帖子
  • 普通邮件
  • 普通邮件

相反:

  • 普通邮件
  • 粘贴的帖子
  • 普通邮件

谢谢您的帮助!

chi*_*jul 5

我的解决方案是http://codex.wordpress.org/Class_Reference/WP_Query

我做了两个查询,在这种情况下,我没有使用分页,也许这可以帮助

    $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;
}
Run Code Online (Sandbox Code Playgroud)