1

WordPress のスティッキー投稿機能で発生している問題についてサポートが必要です。

スティックポストをループの先頭にくっつける方法がわかりません。私は彼に似たループを持っています:

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

そして、私はそれが次のように機能することを望みます:

  • スティッキーポスト
  • 普通郵便
  • 普通郵便

代わりに:

  • 普通郵便
  • スティッキーポスト
  • 普通郵便

助けてくれてありがとう!

4

2 に答える 2

5

ここでの私の解決策http://codex.wordpress.org/Class_Reference/WP_Query

2 つのクエリを作成しました。この場合、ページネーションを使用していません。

    $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;
}
于 2012-01-12T09:43:06.980 に答える
2

デモサイトでこれをテストしました。デフォルトの順序は次のとおりです。 - スティッキー - 通常 - 通常 デフォルトの順序は次のとおりです - 通常 - スティッキー - 通常

Twentyten などの他のテーマでテストすることをお勧めします。そこからおそらく基本的なデバッグがこれをチェックします: http://codex.wordpress.org/Sticky_Posts

于 2011-09-07T21:16:25.357 に答える