How to Remove the Posts per page limit in Wordpress

I love Wordpress, it’s made web publishing and blogging incredibly easy and available for so many people.

But, Depending on your theme or setup, it’s also easy to make hundreds of pages of duplicate content within your own domain. For instance under the categories pages, by default your content is duplicated and paginated based on your posts_per_page setting. So some of your older posts can be incredibly difficult for users and search engines to get to.

My goal was to fix this using these two changes:

  • Make the category pages into lists of links so that it doesn’t show up as duplicate content.
  • Have each category page show every article in that category, overriding the “Show at most” setting, so that from any page on the site, you are never more than 2 clicks away from any other page.

Read on for how I did it…

Removing the posts per page limit

WordPress uses the first Template file it finds in your current Theme’s directory from the following list (assuming this is for category 6).

  1. category-6.php
  2. category.php
  3. archive.php
  4. index.php

So, the easiest way to change the amount of posts per page shown for categories, is to do the following:

  • Either edit your category.php file, or if it doesn’t exist, copy your index.php file to category.php.
  • look for this line:
    < ?php get_header(); ?>
    and change it to the following:
    < ?php get_header(); query_posts( 'posts_per_page=-1&cat=' . $cat ) ?>
  • That’s all, your finished. The -1 in posts_per_page lets Wordpress know you want all posts to be shown and it overrides the setting in your options.

Changing the duplicate content into lists of links

This was also a simple quick change - I again edited my category.php file and looked for the following line:
< ?php if (have_posts()) : ?>
Deleted everything between that if statement and its endif and put in the following:
<h1 id="cat_h1">< ?php single_cat_title() ?></h1>
<ul>
< ?php while (have_posts()) : the_post(); ?>
<div class="post">
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="< ?php _e('Permanent link to'); ?> < ?php the_title(); ?>">< ?php the_title(); ?></a></li>
</div>
< ?php endwhile; ?>
</ul>

With these two easy changes, I now show all posts within my categories regardless of my options settings, and have removed the duplicate content from the category pages by making every category article a link.

If you aren’t already using it, I also recommend the Permalink Redirect Wordpress Plugin to help keep your URL schema straight and to ensure that there is only one URL associated with each blog entry.

Let me know how this works out for you, hopefully you find these changes useful.

3 Responses to “How to Remove the Posts per page limit in Wordpress”

  1. 1
    Martin Says:

    Thanks for the tip.. I am using Andreas09 and have my categories set up as subcategories within parent categories, and wanted to show all post links for the parent and all children. Or just the individual children as desired.
    Was really scratching my head with the max 10 items p/page when by chance ran across your tip.
    It works great and lists as many posts as there are for whatever category or subcategory is chosen..
    Thanks again.

  2. 2
    Presh Says:

    Thank you. I searched for hours until I found your code. It is much appreciated.

  3. 3
    Gyrus Says:

    Thanks! Was looking for a while for how to control posts_per_page on archive pages… This worked a treat.

Leave a Reply

Search

Subscribe!

Subscribe to the RSS Feed

Have a question or comment?

Send me an email - mincus@gmail.com

Most Popular

Recent Posts

Categories

Sponsors

Links

Meta

Classic Kids Games