2012-04-17 13 views
0

希望你們能幫助我。WordPress的兩個類別循環粘滯在開始頁面。分頁錯誤

我有一類兩個非常簡單的自定義循環:一個粘,一個非粘性。我希望粘貼文章只顯示在第一頁上,而不是在分頁時顯示在其餘頁面上。在每個頁面上也必須有正確的8個帖子(包括第1頁上的粘滯帖子)。所有這一切都與我下面的代碼正常工作。

問題是這樣的:第一頁:1個粘&帖子#15- ,兩頁:交# -1。由於粘貼文章,WP跳過第二頁上的一個帖子(#8)。任何人都有這個解決方案?我非常感謝幫助。

<!-- Sticky --> 
<?php if ($paged != True): ?> 
    <?php $wp_query = new WP_Query(array('post__in' => get_option('sticky_posts'), 'category_name' => Work)); ?> 
     <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 
      <?php get_template_part('loop', 'index'); ?> 
     <?php endwhile; ?> 
    <?php wp_reset_postdata(); // reset the query ?> 
<?php endif ?> 

<?php 
$postcount = $wp_query->post_count; 
$postnumber = 8; 
if ($paged != True){ $postnumber = $postnumber - $postcount; } 
?> 

<!-- Non-Sticky --> 
<?php $wp_query = new WP_Query(array('post__not_in' => get_option('sticky_posts'), 'category_name' => Work, 'posts_per_page' => $postnumber, 'paged' => $paged)); ?> 
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> 
     <?php get_template_part('loop', 'index'); ?> 
    <?php endwhile; ?> 
<?php wp_reset_postdata(); // reset the query ?> 

回答

0

看看我的答案在這裏一個類似的問題: Can post_nav_link navigation work with WordPress custom page templates?
關鍵是offset

+0

感謝您的回答janw!我會試試,並讓你知道它是如何去的。 – Keat 2012-04-17 15:23:18

+0

如果它不工作,讓我知道我 – janw 2012-04-17 16:58:18

+0

不能真正得到它的工作。 Dosent this:'$ offset =($ paged-1)* get_query_var('posts_per_page')'如果第2頁的im和posts_per_page是8,等於8? – Keat 2012-04-17 19:05:06