0

I have the following custom query and im attempting to paginate the links of previous archive posts using the example from the wordpress codex

http://codex.wordpress.org/Function_Reference/paginate_links#Basic_Example

Am i inserting this in the wrong place? I inserted before the end of the query with the basic arguments, and there is just a place space at the moment.

Any advice / tutorial is appreciated.

Update 2: Ive now tried the change in the wp_query in the pagination piece, and still no luck.

<div id = "innerpagemaincontent">
<h2 class="innerpagetitle">Latest News</h2>
    <div class="r-post clearfix">

 <?php // custom loop query
$carouselPosts = new WP_Query('showposts=5');

// Pagination fix
$original_query = $wp_query;
$wp_query = NULL;
$wp_query = $carouselPosts;

// open loop
if ( $carouselPosts ->have_posts() ) : while ( $carouselPosts->have_posts() ) :  $carouselPosts->the_post(); ?>

<div class="otherrecentpostswrap">
   <div id="postdetails"><div class="boldyfont">Posted by <?php the_author(); ?><br/><?php the_category(','); ?></div><a href="<?php the_permalink(); ?>"><?php the_date (); ?></a></div>
    <div class="thumb"><a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail(array(160,160)); ?><span class="overlay">    </span></a></div>

        <div id="postewrapper">
         <div class="recentpostscontent">
        <a href="<?php the_permalink(); ?>">
        <span class="innerpageposttitle"><?php the_title(); ?></a></span>

    <?php the_excerpt(); ?>
    <br/>
    <br/>
    <a class="readmorelink" href="<?php the_permalink(); ?>"> Read More </a>  </div></div>
<br/><br/>


</div>
<?php endwhile; ?>
<?php endif; ?>


<?php paginate_links(  array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $carouselPosts->max_num_pages
    ) ); ?>

<?php wp_reset_query(); ?>
Chip Bennett
  • 55,109
  • 8
  • 91
  • 170
Kirsty Marks
  • 257
  • 1
  • 3
  • 13

2 Answers2

0

One issue at least: you'll want to close the loop before outputting your pagination links, or else they'll be output on every iteration of the loop. But you've got paginate_links() before endwhile;.

Try this arrangement instead:

// open loop
if ( have_posts() ) : while ( have_posts() ) : the_post();

    // Loop markup

// close loop
endwhile; endif;

// pagination here
paginate_links( $args );

For a custom query loop, you'll want to handle the query accordingly:

// custom loop query
$custom = new WP_Query( $args );

// Pagination fix
$original_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom;

// open loop
if ( $custom->have_posts() ) : while ( $custom->have_posts() ) : $custom->the_post();

    // Loop markup

// close loop
endwhile; endif;

// pagination here
paginate_links( $args );

// reset query
wp_reset_query();
Chip Bennett
  • 55,109
  • 8
  • 91
  • 170
0

I copied your code and tried at my localhost. It was not working as $wp_query->max_num_pages is 0 but when i changed to 'total' => $carouselPosts->max_num_pages it showing paging. I hope it will work in your system also. if it doesn't work, let me know, i will try to help again