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

时间:2011-09-07 14:27:38

标签: wordpress sticky

我想获得有关WordPress粘贴帖子功能的问题的帮助。

我无法弄清楚如何让摇杆贴在循环的开头。我有一个类似于他的循环:

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

我希望它能像这样工作:

  • 粘贴帖子
  • 普通帖子
  • 普通帖子

取而代之的是:

  • 普通帖子
  • 粘贴帖子
  • 普通帖子

感谢您的帮助!

2 个答案:

答案 0 :(得分:5)

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

我提出了两个问题,在这种情况下,我不使用分页,this可以提供帮助

    $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;
}

答案 1 :(得分:1)

我在我的演示网站上测试了这个。默认顺序应为:   - 粘   - 平凡   - 平凡 默认顺序是NOT   - 平凡   - 粘   - 普通

我建议用其他主题进行测试,比如二十几岁。 从那里它可能是基本的调试 检查一下: http://codex.wordpress.org/Sticky_Posts