[resolved] Disabling pagenumbers/pagination with WP_Query (6 posts)

  1. LaDoza
    Posted 6 years ago #


    I'm trying to stop the pagenumbers from showing when using WP_Query to show posts from a category. I only want to show the 3 most recent posts and don't want the option to go to any other page.
    I'm using the following code:

    $wp_query = new WP_Query();
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
     <li><a href="<?php the_permalink(); ?>">
              <?php the_title(); ?>
              </a>  </li>
    <?php endwhile; ?>

    I've tried different parameters like is_paged and paged, but that doesn't seem to do what I'm trying to achieve.
    Any help would be greatly appreciated!


  2. MichaelH
    Posted 6 years ago #

    Well the option to go to another page really isn't provided by query_posts, but some other thing like template tag, previous_posts_link() and next_posts_link(), or a plugin such as wp-pagenavi.

  3. LaDoza
    Posted 6 years ago #

    Thanks for your reply.
    But I don't understand, why does a pagenumber show up when I use the posted code? I am not using any navigation plugins and I'm not calling any navigational functions.

  4. MichaelH
    Posted 6 years ago #

    Deactivate plugins and change to the WordPress Default theme to see if the problem persists.

  5. LaDoza
    Posted 6 years ago #

    There indeed are no pagenumbers when the default theme is activated. Hmm must really be something template-related then, I'll go try and find it. Thanks for pointing me in the right direction!

    [Edit] It's weird though, I made my template from scratch and don't recall building in any pagination functions. I hope I'll find what is causing it (plugins are deactivated).

  6. LaDoza
    Posted 6 years ago #

    Found it!

    I used the above code in a file called news.php and included that on my postpage using echo include (TEMPLATEPATH . '/news.php');

    I changed that to include (TEMPLATEPATH . '/news.php'); (dropped the echo) and now the number's gone. Had nothing to do with the wp_query function at all :)

    Thanks for your replies

Topic Closed

This topic has been closed to new replies.

About this Topic