My advice would be to never use query_posts
. Instead use a custom query or the pre_get_posts
hook for both instances and always make sure you call wp_reset_postdata
after your custom query.
BUT becase your nav function references the global $wp_query
, you would have to use query_posts
passing the paged
parameter to it.
<?php get_header(); ?>
<div class="row post-carousel">
<?php
$args = array(
'posts_per_page' => '3',
);
$query = new WP_query ( $args );
if ( $query->have_posts() ) { ?>
<?php while ( $query->have_posts() ) : $query->the_post(); /* start the loop */ ?>
<div class="col-xs-12 col-sm-4">
<article id="post-<?php the_ID(); ?>" <?php post_class( 'most-recent' ); ?>>
<?php if ( has_post_thumbnail() ) { ?>
<a href="https://wordpress.stackexchange.com/questions/253631/<?php the_permalink(); ?>">
<div class="post-thumbnail-img"><?php the_post_thumbnail('index-carousel'); ?></div>
</a>
<?php } ?>
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
</article><!-- #post-## -->
</div>
<?php // End the loop.
endwhile;
wp_reset_postdata();
} ?>
</div>
<div class="row newsletter-container">
<div class="newsletter col-sm-12 col-md-6">
<p>Sign up for my newsletter, for all the latest updates!</p>
</div>
<div class="newsletter col-sm-12 col-md-6">
<!-- Begin MailChimp Signup Form -->
<!-- code goes here -->
<!--End mc_embed_signup-->
</div>
</div>
<?php
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$second_args = array(
'posts_per_page' => 3,
'offset' => 3,
'paged' => $paged
);
query_posts($second_args);
if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; wp_reset_postdata(); ?>
<?php _tk_content_nav( 'nav-below' ); ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
<?php get_footer(); ?>