• I have a custom category template (i.e. category-events.php) setup and it works fine except when I try to go to the next page. It just repeats the same posts from the first page of the category and displays the option to “go back”.

    Here is the code I am using on the custom category page:

    <?$my = new WP_Query('category_name=Previous Events&showposts=5&orderby=date&order=DESC')?>
    				<?php if ($my->have_posts()) : ?>
    					<div class="events previous">
    						<h2><?php if(function_exists('bcn_display')) {bcn_display();}?></h2>
    							<div class="holder">
    
    						<?php while ($my->have_posts()) : $my->the_post(); ?>
    							<?$more=0?>
    							<div class="event">
    								<?if (get_post_meta(get_the_ID(), "Little Image", true)):?>
    								<div class="holder-img">
    									<a href="<?php the_permalink()?>">
    										<img src="<?php echo get_meta_image_url(get_post_meta(get_the_ID(), "Little Image", true))?>" width="100" height="100" alt="#" />
    										<?if (get_post_meta(get_the_ID(), "Date Small", true)):?>
    										<span class="date"><?php echo get_post_meta(get_the_ID(), "Date Small", true)?></span>
    										<?endif;?>
    										<span class="b-shadow"><span>&nbsp;</span></span>
    									</a>
    								</div>
    								<?endif;?>
    
    								<div class="text-hold">
    									<h3><a href="<?the_permalink()?>"><?the_title()?></a></h3>
    									<span class="event-date"><?php echo get_post_meta(get_the_ID(), "Date Large", true)?> |</span>
    									<?the_excerpt()?>
    									<span class="links"><a href="<?php the_permalink()?>">Read more</a> | <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><?php the_tags(' | Sponsored by: ', ', '); ?> </span>
    								</div>
    							</div>
    							<?endwhile;?>
    
    						</div>
    					</div>
    				<?endif;?>
    
    				<div class="navigation"><p><?php posts_nav_link(); ?></p></div>

    Thanks for any help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Try:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $my = new WP_Query('category_name=Previous Events&showposts=5&orderby=date&order=DESC&paged=' . $paged)?>
    Thread Starter dlogan

    (@dlogan)

    Thanks Esmi,

    That fixed the second page with one exception, it only has the “previous page” option on it. However there are 4 or 5 pages in total. I manually entered the url for the subsequent pages and they have the correct posts on them, just no “next page” only “previous page”.

    Any ideas on that? Thanks again.

    I prefer to use next_posts_link and previous_posts_link instead of posts_nav_link. Have to you tried that approach?

    Thread Starter dlogan

    (@dlogan)

    Hi Esmi,

    Thanks for the help, but that didn’t work. Here is what I am referring to:

    https://aiga.inovat.us/category/previous-events

    If you go to the “Older Events” at the bottom it goes to page 2, but you can never get to page 3 or 4…

    Here is the code of that page:

    <?php get_header();?>
    	<div id="content-home">
    
    				<?$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    				$my = new WP_Query('category_name=Previous Events&showposts=5&orderby=date&order=DESC&paged=' . $paged)?>
    				<?php if ($my->have_posts()) : ?>
    					<div class="events previous">
    						<h2><?php if(function_exists('bcn_display')) {bcn_display();}?></h2>
    							<div class="holder">
    
    						<?php while ($my->have_posts()) : $my->the_post(); ?>
    							<?$more=0?>
    							<div class="event">
    								<?if (get_post_meta(get_the_ID(), "Little Image", true)):?>
    								<div class="holder-img">
    									<a href="<?php the_permalink()?>">
    										<img src="<?php echo get_meta_image_url(get_post_meta(get_the_ID(), "Little Image", true))?>" width="100" height="100" alt="#" />
    										<?if (get_post_meta(get_the_ID(), "Date Small", true)):?>
    										<span class="date"><?php echo get_post_meta(get_the_ID(), "Date Small", true)?></span>
    										<?endif;?>
    										<span class="b-shadow"><span>&nbsp;</span></span>
    									</a>
    								</div>
    								<?endif;?>
    
    								<div class="text-hold">
    									<h3><a href="<?the_permalink()?>"><?the_title()?></a></h3>
    									<span class="event-date"><?php echo get_post_meta(get_the_ID(), "Date Large", true)?> |</span>
    									<?the_excerpt()?>
    									<span class="links"><a href="<?php the_permalink()?>">Read more</a> | <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><?php the_tags(' | Sponsored by: ', ', '); ?> </span>
    								</div>
    							</div>
    							<?endwhile;?>
    
    						</div>
    					</div>
    				<?endif;?>
    
    				<div class="navigation"><p><?php previous_posts_link('< Newer Events', '0') ?> <?php next_posts_link('Older Events >', 0); ?></p></div>
    
    			</div>
    			<?get_sidebar()?>
    	</div>
    <?php get_footer(); ?>

    Thanks for any help.

    Not sure this is your problem but showposts=5 should probably be posts_per_page=5

    See Template_Tags/query_posts#Pagination_Parameters

    Thread Starter dlogan

    (@dlogan)

    Tried that, but its still not working.

    Any other ideas?

    Works just fine for me. Maybe a plugin causing your problem.

    I’m using the WordPress Default Theme, no plugins, default permalinks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom category page not paginating properly’ is closed to new replies.