WordPress.org

Ready to get started?Download WordPress

Forums

Limiting Search Page Posts to 10 Per Page from Infinite (9 posts)

  1. Schillingry
    Member
    Posted 1 year ago #

    Hey Guys,

    I'm trying to limit the amount of posts per page on my website. Currently when you type something in the search bar it lists every post from the beginning of time. I'd like it to be 10. Here's how my code reads:

    <?php if (have_posts()) : ?>
    <div id="left" class="pageContentArea">
    <article class="post">
    <h1>Results for '<?php the_search_query(); ?>'</h1>
    <?php include (TEMPLATEPATH . '/_/inc/post/nav.php' ); ?>
    <?php while (have_posts()) : the_post(); ?>
    <article <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <div class="entry">
    <?php the_excerpt(); ?>
    </div>
    </article>
    <?php endwhile; ?>
    <?php include (TEMPLATEPATH . '/_/inc/post/nav.php' ); ?>

    Do you have any reccommendations on what I need to add in order to achieve this?

  2. Ryan Yu
    Member
    Posted 1 year ago #

    Hi Schillingry,

    Have you tried updating the setting on your backend?

    Go to Settings > Reading and see what value you have for "Blog pages show at most".

  3. Schillingry
    Member
    Posted 1 year ago #

    Hey Ryan,

    Yeah, currently that reads 5 which is how the News page outputs. However on the search results page it shows every post from the most recent to the oldest. I just want to make it to where only the 10 show and if you want to see more you click to another page.

    Right now about 300 show so the page is crazy long. Any suggestions?

  4. Ryan Yu
    Member
    Posted 1 year ago #

    Could you post the url for the search result page?
    Also can you post the code from search.php using pastebin.com?

    Thanks!

  5. Schillingry
    Member
    Posted 1 year ago #

    Hey Ryan,

    Thanks for your help. Here is the pastebin.com url of the search.php

    http://pastebin.com/iZrgA3Fu

    The url to the search results page is http://www.austinfilmfestival.com/?s=interview

    I'm looking into it as well, however any help is greatly appreciated!

  6. Schillingry
    Member
    Posted 1 year ago #

    Hey Ryan,

    I think I was able to get it corrected. I added:

    <?php query_posts($query_string . '&showposts=10'); ?>

    Right above the
    <?php if (have_posts()) : ?>

    and it looks like it is only displaying 10 now.

  7. Ryan Yu
    Member
    Posted 1 year ago #

    Hi Schillingry,

    Find the line

    <?php if (have_posts()) : ?>

    and add the code below above the line

    <?php query_posts($query_string . '&showposts=20'); ?>

    20 is the number of posts you want to display.

    Let me know how it goes.

  8. Ryan Yu
    Member
    Posted 1 year ago #

    Oops, you've already figured it out haha

  9. Schillingry
    Member
    Posted 1 year ago #

    Great, looks like we came up with the same thing.

    Thank you very much for looking into this with me!

Topic Closed

This topic has been closed to new replies.

About this Topic