1

Can anyone please shed some light as to why the following to print out page numbers works on my local dev server but not on my live server?

Both server are running same version of PHP.

My Loop

<?php
global $paged;
$args = array(
    'orderby' => 'post_date',
    'posts_per_page' => 5,
    'paged' => $paged
);
$query = new WP_Query($args);
if($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
//do stuff
endwhile; ?>

My Pagination

<?php echo '
<div id="pagination">
<a class="first page button" href="'.get_pagenum_link(1).'">[First]</a>';
for($i=1;$i<=$query->max_num_pages;$i++)
echo '<a class="page button" href="'.get_pagenum_link($i).'">'.$i.'</a>';
echo '<a class="last page button" href="'.get_pagenum_link($query->max_num_pages).'">[Last]</a></div>
';
endif;
wp_reset_query();
?>

The issue clearly lies within:

for($i=1;$i<=$query->max_num_pages;$i++)

The first & last print out fine - the page numbers do not.

Thanks in advance

EDIT

If i do this it works:

for($i=1;$i<=99;$i++)

So the issue is with:

$query->max_num_pages;

Any more thoughts?

11
  • Well, I just copied the code and it works (unfortunately? ;)) just fine for my demo website.
    – tfrommen
    Apr 9, 2013 at 16:40
  • Haha, thanks for that, hence why i'm banging my head off the desk with this right now.
    – Danny
    Apr 9, 2013 at 16:42
  • Have you tried disabling all plugins? Does WPDEBUG output anything? Apr 9, 2013 at 17:06
  • Didn't help, but thanks for the suggestion @user2019515 - I'm syncing my local version with live dev via git so the installs are identical, i'm baffled!
    – Danny
    Apr 9, 2013 at 17:23
  • Dev and live both using linux/windows?
    – vancoder
    Apr 9, 2013 at 18:19

1 Answer 1

0

try this

<?php 
//global $wp_rewrite;
$loop->query_vars['paged'] > 1 ? $current = $loop->query_vars['paged'] : $current = 1;

$pagination = array(
    'base' => @add_query_arg('page','%#%'),
    'format' => '',
    'total' => $loop->max_num_pages,

    'current' => 0,
    'show_all' => true,
    'prev_next'    => true,
    'prev_text'    => __('&laquo; Back'),
    'next_text'    => __('Newxt&raquo;'),
    'type' => 'plain'
    );

if( $wp_rewrite->using_permalinks() )
    $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged    ' );    

    echo "<div class=\"pagination\" >";    
echo paginate_links( $pagination );    
echo "</div>";    
?>    
1
  • How does this help? Please explain.
    – vancoder
    Apr 9, 2013 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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