• Hi I have a pagination working with Previous and Next.
    But after adding several posts, the prev, and next loop only contains a specific number of posts.
    I’ve looked at the category page, and have realized this number is equal to the loops on that page. Meaning, my loop is spitting out all the posts(to the category I have set) that are “new” and not showing the “older posts.
    here is a link to the category page. the loop I’ve made is dynamic, it’s in the sidebar.

    https://ucanusenglish.cn/category/events/

    here’s my loop code.

    <?php wp_reset_postdata();
      // set up or arguments for our custom query
      $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
      $query_args = array(
        'post_type' => 'post',
        'category_name' => 'events',
        'posts_per_page' => 1
      );
    
      $this_query = new WP_Query( $query_args );
    ?>
    <div  id="eventswidget">
    <?php while ( $this_query->have_posts() ) : $this_query->the_post();  ?>
    
    <div>
    <div style="margin-bottom:10px;line-height: initial;font-weight: bold;">
    <a  href="<?php the_permalink() ?>"><center>
    <img class="eventimg"  style="border-radius: 10px;box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);margin-bottom:8px;margin-top:4px"  width="212" height="137" src="<?php  echo catch_that_image(); ?>" ></center>
    <?php the_title(); ?></a></div>
    <?php  the_excerpt(); ?>
    </div>
    
    <?php endwhile;  wp_reset_postdata();?>
    
    </div>
    <div style="margin-bottom: -80px;padding-top: 30px;">
    <a style="margin-right:120px" id="eventsprev" href="javascript:void(0)"> Previous</a> <a id="eventsnext" href="javascript:void(0)">Next</a>
    </div>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    // set up or arguments for our custom query
      $paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
      $query_args = array(
        'post_type' => 'post',
        'category_name' => 'events',
        'posts_per_page' => 1
      );
    
      $this_query = new WP_Query( $query_args );

    That’s wrong. You’re not using the paged variable, and anyway you’re populating it with the incorrect query var. Try this instead:

    // set up or arguments for our custom query
      $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
      $query_args = array(
        'post_type' => 'post',
        'category_name' => 'events',
        'posts_per_page' => 1,
        'paged' => $paged,
      );
    
      $this_query = new WP_Query( $query_args );
    Thread Starter SteveYantz

    (@steveyantz)

    Thank you, i must have accidentally deleted the paged variable when I was messing with it.
    However, after replacing the code with yours, I still get the same result.
    If I change :

    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

    to

    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 2;

    I get the older posts in the result. But just the older posts.

    How I can I combine the requests?
    page 1 plus page 2?
    or better yet, how can I request -every page?-

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Customized Pagination loop, won't show the "older posts"’ is closed to new replies.