WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the Starkers theme as a foundation to build my theme and I am having difficulty getting my loop.php to paginate posts properly. When I click the "Next" or "Previous" post pagination button, it succeeds in changing the URL to example.com/page/2 however it does not actually load new posts (I have dozens of posts with the category I am querying, so this is not the problem.)

Here is the code I have in my loop.php file. Please let me know if you need me to clarify anything further.

                <?php include('includes/featured-content-slider.php'); ?>

            <!-- 960 16 Column Grid -->
            <div class="container_16"> 

                <!-- Featured News -->
                <section class="grid_11 featured-news">

                    <!-- Featured News Heading -->
                    <!-- /Featured News Heading -->

                        <!-- Featured News Loop -->
                        <?php query_posts('category_name=featured-news'); ?>
                            <?php while ( have_posts() ) : the_post(); ?>
                        <!-- Featured News Loop -->

                        <!-- Post --> 
                        <article class="post" id="post-<?php the_ID(); ?>" <?php post_class(); ?> >

                            <!-- Featured News Title -->
                            <span><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
                            <!-- /Featured News Title -->

                            <!-- Featured News Meta -->
                            <p class="featured-news-post-meta">By <span class="featured-news-author"><?php echo get_the_author(); ?></span> / <?php echo get_the_date('d.m.Y'); ?>
                            <!-- /Featured News Meta -->

                            <!-- Featured News Thumbnail -->
                            <?php the_post_thumbnail(array(640,320)); ?>
                            <!-- /Featured News Thumbnail -->

                            <!-- Featured News Excerpt -->
                            <p class="featured-news-excerpt"><?php the_excerpt(); ?></p>
                            <!-- /Featured News Excerpt -->

                            <!-- Featured News Social Links -->
                            <ul class="featured-news-social-media-links">
                                <a href="#"><li class="facebook-share-post"></li></a>
                                <a href="#"><li class="twitter-post"></li></a>
                                <a href="#"><li class="google-plus-post"></li></a>
                                <a href="#"><li class="facebook-like-post"></li></a>
                                <a href="<?php the_permalink(); ?>"><li class="comment-post"></li></a>
                            <!-- /Featured News Social Links -->

                        <!-- /Post -->

                            <?php endwhile; ?>
                            <!-- /Featured News Loop -->

                    <!-- Pagination -->
                    <?php if ($wp_query->max_num_pages > 1) : ?>
                        <div class="pagination grid_3">
                            <?php next_posts_link( __( '&larr; Older News', 'twentyten' ) ); ?>
                        <div class="pagination grid_3 push_6">
                            <?php previous_posts_link( __( 'Newer News &rarr;', 'twentyten' ) ); ?>
                    <?php endif; ?>
                    <!-- /Pagination -->

                <!-- /Featured News -->

                <!-- Other News -->
                <aside class="grid_5 push_1 other-news">

                    <!-- Other News Heading -->
                    <!-- /Other News Heading -->

                        <!-- Other News Loop -->
                        <?php query_posts('category_name=other-news&showposts=6'); ?>
                        <?php while (have_posts()) : the_post(); ?>

                        <!-- Other News List -->
                            <li><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
                            <li class="other-news-post-date"><?php echo get_the_date('d.m.Y'); ?>
                        <!-- /Other News List -->

                        <?php endwhile; ?>
                        <?php wp_reset_query(); ?>
                        <!-- /Other News Loop -->

                        <!-- View More -->
                        <div class="view-more">
                            <a href="/other-news">View More &rarr;</a>
                        <!-- /View More -->

                <!-- /Other News -->

            <!-- /960 16 Column Grid -->
share|improve this question
Did you try searching the site before posting? The question of custom loop pagination has been asked several times already. – Chip Bennett Jun 9 '12 at 17:08
possible duplicate of Pagination not working with custom loop – Chip Bennett Jun 9 '12 at 17:09

I don't know what's inside featured-content-slider.php, but I'm assuming this is the loop you'd like to paginate:


The issue is that by calling query_posts like this in the template, you're overwriting the original query for the page and not setting any page parameter. Your two options are to either modify the original query string, stored in the global variable query_string:

query_posts( $query_string . '&category_name=featured-news' );

or a better method is to modify the query with an action hook before it happens, so you're not simple overwriting the original. This example would go in your theme's functions.php, here we check if it's the home page and modify the query by setting category name:

function wpa54691_filter_pre_get_posts( $query ) {
    if ( $query->is_home ) {
        $query->set( 'category_name', 'featured-news' );
    return $query;
add_filter( 'pre_get_posts', 'wpa54691_filter_pre_get_posts' );

For additional queries, like this one further down:


You should use a new instance of WP_Query instead.

$args = array(
    'posts_per_page' => 6,
    'category_name' => 'other-news'
$other_news = new WP_Query( $args );
while( $other_news->have_posts() ):

If you're also using query_posts within featured-content-slider.php, you'll need to change that as well so as not to interfere with your primary loop.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.