Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Below is a snippet of code that appears on one of my pages called: Featured. I created a template and then respectively created a page and activated the template in the wp-admin. However when I click the button to paginate to page 2, which looks something like: http://example.com/featured/page/2 the next page shows up blank with no content (and I have plenty of content in the respective categories to display.) Any ideas what could be wrong here? Let me know if you need further clarification with my issue and/or code.

All Features

<!-- Featured Loop -->
<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
            'post_type'=> 'post',
        'category_name' => 'featured-content, podcast',
        'posts_per_page' => 10,
        'paged'=> $paged
    );
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query($args);
    if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
    if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail('featured'); ?>
    </a>
    <div class="meta">
        <p class="title"><?php the_title(); ?></p>
        <br>
        <p class="author">By <?php the_author(); ?></p>
    </div>
</article>

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

<!-- Older/Newer Pagination -->
<?php if ($wp_query->max_num_pages > 1) : ?>
    <?php next_posts_link( __( '<span class="arrow">&larr;</span> Older' ) ); ?>
    <?php previous_posts_link( __( 'Newer <span class="arrow">&rarr;</span>' ) ); ?>
<?php endif; ?>
<!-- /Older/Newer Pagination -->

<?php
/* PageNavi at Bottom */
    if (function_exists('wp_pagenavi')){wp_pagenavi();}
    $wp_query = null;
    $wp_query = $temp;
    wp_reset_query();
?>
<!-- /Featured Loop -->

share|improve this question
add comment

3 Answers

your code was a bit messy but working for me.

I cleaned a bit and it works fine for me. I used on a clean install of WP 3.5 with the WP-PageNavi plugin.

I used 2 categories (test, news) and 1 post per page so you'll have to change it to your needs.

<?php

$temp = $wp_query;
$wp_query = null;
$wp_query_args = array( 
                    'post_type'=> 'post',
                    'category_name' => 'news, test',
                    'posts_per_page' => 1,
                    'paged'=> $paged
                );
$wp_query = new WP_Query( $wp_query_args );
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail('featured'); ?>
    </a>
    <div class="meta">
        <p class="title"><?php the_title(); ?></p>
        <br>
        <p class="author">By <?php the_author(); ?></p>
    </div>
</article>

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

<?php wp_pagenavi(); ?>

<?php 
  $wp_query = null; 
  $wp_query = $temp;  // Reset
?>
share|improve this answer
    
do you have the code for wp_pagenavi() function? Come to think of it, this might be why mine isn't working because it's calling an undefined function...Is this a WordPress core function? –  Brian Jan 8 '13 at 16:27
    
well, your code was working for me with the "<!-- Older/Newer Pagination -->" solution. I find the wp_pagenavi solution easier: it's just a simple plugin: [wordpress.org/extend/plugins/wp-pagenavi/] –  molokom Jan 8 '13 at 16:34
add comment

In functions.php

function my_theme_navigation() 
{ 
    global $shortname;

    if( get_option( $shortname . '_next_prev_or_paginate' ) == 'Next' ) : 
        // the block for next-prev navigation
        echo '<div style="float:left">';
        next_posts_link('Older');
        echo '</div>';
        echo '<div style="float:right">';
        previous_posts_link ('Newer');
        echo '</div>';
    else : 
        // the block for pagination
        global $wp_query;
        $big = 999999999; // need an unlikely integer
        echo paginate_links(
            array(
                'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                'format' => '?paged=%#%',
        'end_size'     => 1,
        'mid_size'     => 2,
                'current' => max( 1, get_query_var('paged') ), 
                'total' => $wp_query->max_num_pages
            )
        ); 
    endif; 
}

Then replace

<!-- Older/Newer Pagination -->
<?php if ($wp_query->max_num_pages > 1) : ?>
    <?php next_posts_link( __( '<span class="arrow">&larr;</span> Older' ) ); ?>
    <?php previous_posts_link( __( 'Newer <span class="arrow">&rarr;</span>' ) ); ?>
<?php endif; ?>
<!-- /Older/Newer Pagination -->

<?php
/* PageNavi at Bottom */
    if (function_exists('wp_pagenavi')){wp_pagenavi();}
    $wp_query = null;
    $wp_query = $temp;
    wp_reset_query();
?>

WITH...

<?php my_theme_navigation(); ?>
share|improve this answer
add comment

I turned on debug in wp-config.php and it turns when my page would paginate, for example featured/page/2, the code breaking after the head loaded as an undefined function was being called. I commented out this function call in my functions.php and now my original code works. Thank you all for your help.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.