2011-09-07 64 views
1

我想獲得關於WordPress博客貼子功能問題的幫助。在循環中發佈第一篇文章 - WordPress

我無法弄清楚如何使棍棒貼到循環的開始。我也有類似的一環,以他:

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

,我想它是這樣工作的:

  • 置頂後
  • 平凡的崗位上
  • 平凡的崗位上

相反用於:

  • 平凡的崗位
  • 置頂後
  • 平凡的崗位上

感謝您的幫助!

回答

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; 
} 
+0

在我的「工具箱」主題的默認index.php的順序把粘性帖子放在頂部,但在我自己的WP_query我不能使它 – chilljul

+0

分類篩選例如對於類別是這樣打破的。您可以添加到查詢參數:'tax_query'=> array('taxonomy'=> get_queried_object() - > taxonomy,'field'=>'id','terms'=> get_queried_object() - > term_id) ) http://wordpress.stackexchange.com/questions/102346/how-to-display-post-from-current-taxonomy-in-archive-page – netAction

1

我在我的演示網站上測試了這個。而默認的順序應該是: - 粘 - 普通 - 普通 默認順序並不 - 普通 - 粘 - 普通

我建議與其他主題的測試它,就像twentyten。 從那裏它可能是基本的調試 檢查: http://codex.wordpress.org/Sticky_Posts

相關問題