7

Currently my website archive page is showing 5 post per page. I need to set it to 100 post per page.

(My home page showing 5 post per page and I don't want change it)

Here is my archive.php

    <?php get_header(); ?>
    <?php do_atomic( 'before_content' ); // my-life_before_content ?>

    <div id="content">
    <?php if (have_posts()) : ?>

      <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
      <?php /* If this is a category archive */ if (is_category()) { ?>
        <h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category</h2>
      <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
        <h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>
      <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
        <h2>Archive for <?php the_time('F jS, Y'); ?></h2>
      <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
        <h2>Archive for <?php the_time('F, Y'); ?></h2>
      <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
        <h2>Archive for <?php the_time('Y'); ?></h2>
      <?php /* If this is an author archive */ } elseif (is_author()) { ?>
        <h2>Author Archive</h2>
      <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
        <h2>Blog Archives</h2>
      <?php } ?>

        <?php if ( is_paged() || count($posts) >= get_option('posts_per_page') ) : ?>
            <div class="post_meta archive_pagination">

                <div class="left"><?php next_posts_link('&laquo; Older Entries') ?></div>
                <div class="right"><?php previous_posts_link('Newer Entries &raquo;') ?></div>

                <div class="clearer">&nbsp;</div>

            </div>

        <?php else : ?>
        <div class="content_separator"></div>

        <?php endif;?>      

        <?php while (have_posts()) : the_post(); ?>

        <div class="archive_post">

            <div class="archive_post_date">
                <div class="archive_post_day"><?php the_time('j') ?></div>
                <div class="archive_post_month"><?php echo strtoupper(get_the_time('M')); ?></div>
            </div>

            <div class="archive_post_title">
                <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <div class="post_date">Posted in: <div class="freetory"><?php the_category(', ') ?></div> |<div class="freetory"><?php the_tags(' '); ?></div></div>
            </div>

            <div class="clearer">&nbsp;</div>

        </div>

        <?php endwhile; ?>

        <?php if ( is_paged() || count($posts) >= get_option('posts_per_page') ) : ?>

            <div class="post_meta archive_pagination">

                <div class="left"><?php next_posts_link('&laquo; Older Entries') ?></div>
                <div class="right"><?php previous_posts_link('Newer Entries &raquo;') ?></div>

                <div class="clearer">&nbsp;</div>

            </div>

        <?php endif;?>

    <?php else : ?>     
        <p>No posts found.</p>

    <?php endif; ?>
    <?php do_atomic( 'close_content' ); // my-life_close_content ?>

        <?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>

    </div><!-- #content -->

    <?php do_atomic( 'after_content' ); // my-life_after_content ?>

<?php get_footer(); // Loads the footer.php template. ?>

I've created the archive page via two themes "Omega" + Quietude

  • do_atomic() is no WP core function, but theme or plugin specific. Please ask at their support route how to achieve that. – kaiser Jul 22 '14 at 12:38
  • @kaiser ..its not a theme file.. but i copy-pasted its from other site(reason is "just want to show post title,not full post in archive page").. – new dev Jul 22 '14 at 13:19
  • "copy/pasted it from other site" ... nice. not. Every content has a license. Please search it up, file an edit and add a link to the source and tell about its license. You must respect other peoples work and intellectual property. For example: Every code on this site is CC-BY-SA 3.0 licensed (see the footer). – kaiser Jul 22 '14 at 13:23
  • source added.... – new dev Jul 22 '14 at 13:44
  • Please don't post thanks you as an answer. Please accept Brad's answer by clicking on the checkmark next to his answer. – Pieter Goosen Jul 23 '14 at 9:52
24

You can use pre_get_posts in your functions file to alter the query

function wpsites_query( $query ) {
if ( $query->is_archive() && $query->is_main_query() && !is_admin() ) {
        $query->set( 'posts_per_page', 100 );
    }
}
add_action( 'pre_get_posts', 'wpsites_query' );
  • Lol, pleasure, upvoted you. Still is the best solution – Pieter Goosen Jul 22 '14 at 14:50
  • This is the best solution. – Amir5000 Apr 4 '18 at 23:21
0

Easiest thing to do rather than edit theme files (and if you're new to WordPress) is to use a plugin like Custom Post Limits « WordPress Plugins.

You can change post limits for any parameter: home page posts, search results, archive results, categories, authors, etc. It's a lightweight plugin that is very versatile.

(And make a child theme if you're editing theme files: Child Themes « WordPress Codex)

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.