0

I've got a page where I only want to display one post per page with pagination at the bottom to go to the next/ previous post. This is my code:

  <?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : '1';
$args = array (
    'nopaging'               => false,
    'paged'                  => $paged,
    'posts_per_page'         => '1',
    'post_type'              => 'post',
    'category_name'          => 'enforcement',
);
?>
    <?php 
     $wp_query = new WP_Query($args);
    ?>

    <?php if ( $wp_query->have_posts() ) : ?>
    <?php while ( $wp_query->have_posts() ) : the_post(); ?>   
<!--<div class="case-studies-text-banner">
   <img src="http://www.mariadev.co.uk/wp-content/uploads/2017/05/case-study-layer.png"/>
    <div class="case-study-title"><?php the_title(); ?></div>
    <div class="case-study-pdf"><?php if (function_exists("wpptopdfenh_display_icon")) echo wpptopdfenh_display_icon();?></div>
    </div>-->

    <?php the_content(); ?>

    <?php endwhile; ?>

<?php next_posts_link( 'Older Entries »', $query->max_num_pages ); ?>


     <?php wp_reset_postdata(); ?>
    <?php else : ?>
    <p><?php __('No News'); ?></p>
    <?php endif; ?>

It does only show 1 post on the first page but when clicking on older posts and moving to this url www.testing./?cat=8&paged=2 no posts show even though there are 3 posts in this category. Any ideas what I'm doing wrong?

0

Try this as your $paged init

<?php global $paged; ?>
<?php 
  if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
  elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
  else { $paged = 1; }  
?>
0

Please Add this line and Check.

<?php previous_posts_link( 'Newer posts' ); ?>

For More Information Please check this LINK

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.