WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. LaDoza
    Member
    Posted 4 years ago #

    Hi,

    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:

    <?php
    $wp_query = new WP_Query();
    $wp_query->query('category_name=NEWSITEMS&showposts=3');
    ?>
    <?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!

    LaDoza

  2. MichaelH
    Member
    Posted 4 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
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

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

  5. LaDoza
    Member
    Posted 4 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
    Member
    Posted 4 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