I'm almost finished with this one, just a small problem left. Hope you can help me.
I've got two very simple, custom loops. One for sticky posts, and one for non-sticky. I've manage to get the sticky posts to only show up on page 1, and not on the rest of the pages (when using pagination), which is just what I want. The problem is this: If I use posts_per_page set to 8, and have 1 sticky post in my database, I get 9 posts on the first page, and 8 on the rest of the pages.
I've managed to change the posts_per_page value with this script in between the loops:
$postcount = $wp_query->post_count;
$postnumber = 8;
if ( $paged != True ){ $postnumber = $postnumber - $postcount; }
and it almost work. If I have 1 sticky post and post 15-9 on the first page, and then click the next button, WP skips post #8 and only shows 7-1 on the next page.
Here is my code:
<!-- 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 ?>
<?php get_template_part( 'loop', 'index' ); ?>to load how the content is shown. I Also have single.php, archive.php, page.php and so on to show a diffrent layout there. – Keat Apr 16 '12 at 12:48