Static front page with recent posts pagination

Is it possible to include index pagination on a static front page?

I have a child theme of twenty eleven and I am attempting to have a home page where there is a slider for sticky posts followed by the recent posts with a custom query, that I would like to be paginated.

I created a page template, and set that page template to be the static front page.

For some reason, pagination only works when I am logged in to WordPress. If I visit the site as an anonymous visitor, I get a 404 and the URL looks like “example.com/2011/09/268” instead of “example.com/page/2”.

Am I going about this the completely wrong way?

Below is the code for the page template:

<?php
get_header(); ?>

        <div id="primary">
            <div id="content" role="main">

                <?php the_post(); ?>

                <?php
                    $sticky = get_option( 'sticky_posts' );

                    // Proceed only if sticky posts exist.
                    if ( ! empty( $sticky ) ) :

                    $featured_args = array(
                        'post__in' => $sticky,
                        'post_status' => 'publish',
                        'posts_per_page' => 10,
                        'no_found_rows' => true,
                    );

                    // The Featured Posts query.
                    $featured = new WP_Query( $featured_args );

                    // Proceed only if published posts exist
                    if ( $featured->have_posts() ) :

                    $counter_slider = 0;

                    ?>


                <div class="featured-posts">
                    <h1 class="showcase-heading"><?php _e( 'Featured Posts', 'twentyeleven' ); ?></h1>

                <div class="flexslider">
                  <ul class="slides">
                <?php
                    // Let's roll.
                    while ( $featured->have_posts() ) : $featured->the_post();

                    if ( has_post_thumbnail()) : ?>
                    <li>
                        <a href="https://wordpress.stackexchange.com/questions/45104/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
                           <?php the_post_thumbnail(); ?>
                           <p class="flex-caption"><a href="https://wordpress.stackexchange.com/questions/45104/<?php the_permalink(); ?>"
                            title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ),
                            the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
                            <?php the_title(); ?></a></p>
                       </a>
                    </li>
                    <?php
                    endif; // End check for post thumbnail ?>
                <?php endwhile; ?>
                  </ul>
                </div>

                <?php //endif; // End check for more than one sticky post. ?>
                </div><!-- .featured-posts -->
                <?php endif; // End check for published posts. ?>
                <?php endif; // End check for sticky posts. ?>

                <?php
                    // Display our recent posts
                    // Setup for pagination of custom loop
                    $paged = (get_query_var('page')) ? get_query_var('page') : 1;

                    $recent_args = array(
                        'order' => 'DESC',
                        'post__not_in' => get_option( 'sticky_posts' ),
                        'category__not_in' => array( 46, 47 ),
                        'tax_query' => array(
                            array(
                                'taxonomy' => 'post_format',
                                'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
                                'field' => 'slug',
                                'operator' => 'NOT IN',
                            ),
                        ),
                        'posts_per_page' => 10,
                        'paged' => $paged,
                    );

                    // Our new query for the Recent Posts section.
                    query_posts( $recent_args );

                    // The first Recent post is displayed normally
                    //if ( $wp_query->have_posts() ) : $wp_query->the_post();
                    ?>
                    <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1>
                    <?php twentyeleven_content_nav( 'nav-above' ); ?>
                    <div class="recent-posts">
                    <?php
                        if ( $wp_query->have_posts() ) :
                        while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
                            <div class="recent-post">
                            <?php if ( "image" == get_post_format() ) :

                                get_template_part( 'content', 'image' );
                            else : ?>
                                <h2 class="entry-title">
                                    <a href="https://wordpress.stackexchange.com/questions/45104/<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
                                </h2>
                                <div class="entry-meta">
                                    <?php twentyeleven_posted_on(); ?>
                                </div><!-- .entry-meta -->
                                <?php if( has_post_thumbnail() ) : ?>
                                    <a href="https://wordpress.stackexchange.com/questions/45104/<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
                                    <?php the_post_thumbnail('excerpt-thumbnail', array('class' => 'alignleft') ); endif; ?></a>
                                <?php the_excerpt(); ?>
                                <p class="comments-link">
                                        <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a Comment', 'twentyeleven' ) . '</span>', __( '<b>1</b> Comment', 'twentyeleven' ), __( '<b>%</b> Comments', 'twentyeleven' ) ); ?>
                                </p>
                            <?php endif; ?>
                            </div>
                            <hr />
                        <?php
                        endwhile; ?>
                        <?php
                        endif; ?>
                    <?php
                    twentyeleven_content_nav( 'nav-below' );
                    // Reset because we used query_posts
                    wp_reset_query(); ?>
                    </div> <!-- End recent-posts -->

                <?php //get_template_part( 'content', 'page' ); ?>

                <?php //comments_template( '', true ); ?>

            </div><!-- #content -->
        </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

1 Answer
1

Create a file front-page.php as a copy your index.php. Add the slider code on top of the page. WordPress will now take care of the pagination for you.

If you need the slider on the first page only wrap it into a conditional:

// First page
if ( empty ( $GLOBALS['paged'] ) or 1 == $GLOBALS['paged'] )
{
    // slider code
}
// the regular loop follows

Leave a Comment