First post on this site. Hope to get some help from you guys. Probably a simple answer for you experts.
I have two category's (news & work). I want to show on my index page (wordpress startpage/blog) the five latest news at the top (cat. news). Below that i want to show my post (cat news & work). I also have sticky posts in the work cat, that I want to only on the first page.
I think this means three loops. one for news, one for sticky in work & news, and then one for work & news, none sticky. I can get this to work, but the problem is that my sticky post shows up first on all the pages when I paginate on the index-file (eg. press the read prev post, /page/2, /page/3 etc..
How can I make the sticky post to be sticky only on the first page (index.php)?
Here is my code:
<div id="news">
<?php $wp_query = new WP_Query(array('category_name' => News, 'posts_per_page' => 5)); ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php get_template_part( 'loop', 'index' ); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div><!--#news-->
<div id="work">
<!-- 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(); ?>
<?php endif ?>
<!-- Non Sticky -->
<?php $wp_query = new WP_Query(array('post__not_in' => get_option('sticky_posts'), 'category_name' => Work, 'posts_per_page' => 8, 'paged' => $paged)); ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php get_template_part( 'loop', 'index' ); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div><!--#work-->
Thanks /K
My pagination code:
function pagination() {
global $wp_query;
$total = $wp_query->max_num_pages;
// Only paginate if we have more than one page
if ( $total > 1 ) {
// Get the current page
if ( !$current_page = get_query_var('paged') )
$current_page = 1;
// Structure of “format” depends on whether we’re using pretty permalinks
$permalinks = get_option('permalink_structure');
$format = empty( $permalinks ) ? '&page=%#%' : 'page/%#%/';
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => $format,
'current' => $current_page,
'total' => $total,
'mid_size' => 2,
'prev_next' => False
));
}
}