• Hi guys,
    Ok so I seem to be having a problem getting pagination to even display on a custom page that I have made for the site I have built. Pagination seems to work in the search.php so I know that it works, but I paste the same code into my local news.php page and pagination doesn’t even display at all.
    My url is sheppadviser.com.au
    The page in question is at sheppadviser.com.au/news/local-news/
    and to see the pagination working on the search page visit this link sport search
    The page code is:

    <?php
    // Template Name: local news
    get_header(); ?>
    
    			<!-- Begin Main -->
    			<div id="main">
    
    					<div class="block archive">
    
    						<h3>
    							<?php _e('Local News', 'UMagazine'); ?>
    						</h3>
    
    						<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    						<?php $recent = new WP_Query('cat=19&showposts='.'&paged='.$paged); ?>
    						<?php if ($recent->have_posts()) : while ($recent->have_posts()) : $recent->the_post(); ?>
    						<div id="post-<?php the_ID(); ?>" <?php post_class('block-post-big'); ?>>
    							<?php
    							if(has_post_format('video') || has_post_format('audio') || has_post_format('gallery')) {
    								$icon = '<span class="' . get_post_format($post->ID) . '-icon"></span>';
    							} else {
    								$icon = '';
    							}
    							?>
    							<?php if(has_post_thumbnail()): ?>
    							<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_post_thumbnail('widget-image'); ?></a><?php echo $icon; ?></div>
    
    							<?php endif; ?>
    							<h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2>
    							<span class="block-meta">
    								<span class="heading-author"><?php the_author(); ?></span>
    								<span class="heading-date"><?php the_time('F j, Y'); ?></span>
    								<span class=""></span>
    							</span>
    							<p><?php echo string_limit_words(get_the_excerpt(), 34); ?></p><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>' class="readmore" ><?php _e('Read More', 'UMagazine'); ?></a>
    						</div>
    						<?php endwhile; endif; ?>
    						<div class="pagination">
    						<?php
    							$total_pages = $wp_query->max_num_pages;
    							if ($total_pages > 1){
    								$current_page = max(1, get_query_var('paged'));
    								echo paginate_links(array(
    									'base' => @add_query_arg('paged','%#%'),
    									'format' => 'page/%#%',
    									'current' => $current_page,
    									'total' => $total_pages,
    									'end_size' => 2,
    									'mid_size' => 3,
    									'prev_text' => '<',
    									'next_text' => '>'
    								));
    							}
    						?>
    
    					</div>
    
    					</div>
    
    			</div>
    
    			<!-- End Main -->
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    The code I am using for pagination is:

    <div class="pagination">
    						<?php
    							$total_pages = $wp_query->max_num_pages;
    							if ($total_pages > 1){
    								$current_page = max(1, get_query_var('paged'));
    								echo paginate_links(array(
    									'base' => @add_query_arg('paged','%#%'),
    									'format' => 'page/%#%',
    									'current' => $current_page,
    									'total' => $total_pages,
    									'end_size' => 2,
    									'mid_size' => 3,
    									'prev_text' => '<',
    									'next_text' => '>'
    								));
    							}
    						?>
    
    					</div>

    I have tried several ways to fix the problem. I have used completely different pagination codes, I have tried the plugins and nothing seems to be working. Can somebody please tell me what I am doing wrong here.
    Thanks in advance.

Viewing 1 replies (of 1 total)
  • in the pagination code, you are checking:
    $total_pages = $wp_query->max_num_pages;

    however you are actually not using $wp_query but $recent

    try to change the line to:

    $total_pages = $recent->max_num_pages;

Viewing 1 replies (of 1 total)
  • The topic ‘Pagination not showing on custom page’ is closed to new replies.