- Author:Scott Reilly
- First released:2009-07-16
- Last update:2017-01-22
- Compatibility:WP 4.1 – 4.7.5
- Download:[ zip ]
Independently control the number of posts listed on the front page, author/category/tag archives, search results, etc.
Control the number of posts that appear on the front page, search results, and author, category, tag, and date archives, independent of each other, including specific archives.
By default, WordPress provides a single configuration setting to control how many posts should be listed in each section of your blog. This value applies for the front page listing, author listings, archive listings, category listings, tag listings, and search results. This plugin allows you to override that value for each of those different sections.
Specifically, this plugin allows you to define limits for:
- Authors archives (the archive listing of posts for any author)
- Authors archives non-first-page (when paging through authors archives listings, number of posts listed when not on the first page)
- Author archives (the archive listing of posts for any specific author)
- Categories archives (the archive listings of posts for any category)
- Categories archives non-first-page (when paging through categories archives listings, number of posts listed when not on the first page)
- Category archive (the archive listings of posts for any specific category)
- Day archives (the archive listings of posts for any day)
- Day archives non-first-page (when paging through day archives listings, number of posts listed when not on the first page)
- Front page (the listing of posts on the front page of the blog)
- Front page non-first-page (when paging through front page listings, number of posts listed when not on the first page)
- Month archives (the archive listings of posts for any month)
- Month archives non-first-page (when paging through month archives listings, number of posts listed when not on the first page)
- Search results (the listing of search results)
- Search results non-first-page (when paging through search results listings, number of posts listed when not on the first page)
- Tags archives (the archive listings of posts for any tag)
- Tags archives non-first-page (when paging through tags archives listings, number of posts listed when not on the first page)
- Tag archive (the archive listings of posts for any specific tag)
- Year archives (the archive listings of posts for any year)
- Year archives non-first-page (when paging through year archives listings, number of posts listed when not on the first page)
If the limit field is empty or 0 for a particular section type, then the default post limit will apply. If the value is set to -1, then there will be NO limit for that section (meaning ALL posts will be shown). The Archives Limit value is also treated as the default limit for Day, Month, and Year archives, unless those are explicitly defined.
Find out more at the plugin’s WordPress Plugin Repository page.
Click to see full-size image.
- Whether installing or updating, whether this plugin or any other, it is always advisable to back-up your data before starting
- Install via the built-in WordPress plugin installer. Or download and unzip
custom-post-limits.zipinside the plugins directory for your site (typically
- Activate the plugin through the ‘Plugins’ admin menu in WordPress
- Click the plugin’s
Settingslink next to its
Deactivatelink (still on the Plugins page), or click on the
Post Limitslink, to go to the plugin’s admin settings page. Optionally customize the limits.
Frequently Asked Questions
Q. Does this plugin introduce additional database queries (or excessively burden the primary query) to achieve its ends?
A. No. The plugin filters the posts_per_page setting value (and, when necessary, the LIMIT SQL clause) as used by the primary WordPress post query as appropriate, resulting in retrieval of only the number of posts up to the limit you specified without significant alteration of the primary query itself and without additional queries. Bottom line: this should perform efficiently.
Q. Is this plugin unit-tested?
- Bugfix: Fix error in a unit test due to variable being used before being set.
- Change: Enable more error ourput for unit tests.
- Change: Default
/tmp/wordpress-tests-librather than erroring out if not defined via environment variable.
- Change: Note compatibility through WP 4.7+.
- Change: Update copyright date (2017).
- New: Add class constant
SETTING_NAME(to store setting name) and use it in
- Change: Update plugin framework to 045.
reset_options()resets values saved in the database.
- Change: Note compatibility through WP 4.6+.
- New: Add ‘License’ and ‘License URI’ header tags to readme.
- Introduced support for defining custom limits for custom post type archives.
- Now treat ‘archives_paged_limit’, if specified, as secondary fallback for paged limits for day, month, and year archives.
- Added fairly comprehensive unit tests.
- New: Add support for defining custom limits for custom post type archives.
- New: Add
get_individual_limit_setting_name()as a helper function to determine the individual limit setting name for authors, categories, custom post types, and tags.
- New: Add
has_individual_limits()to indicate if a setting type has individual limits.
- Change: Refactor
custom_post_limits()handling for author, category, and tag individual limits.
- Change: Treat ‘archives_paged_limit’, if specified, as secondary fallback for paged limits for day, month, and year archives.
- Change: On settings page, show help text indicating the value source or default for all (now to include paged) limits.
- Change: Update plugin framework to 044.
- Change: Rearrange when certain hooks are registered.
- Change: Refactor
- Change: Improve singleton implementation.
get_instance()static method for returning/creating singleton instance.
- Make static variable ‘instance’ private.
- Make constructor protected.
- Make class final.
- Additional related changes in plugin framework (protected constructor, erroring
- Fix: Initialize private instance variable
$first_page_offsetto null in
custom_post_limits()to avoid pollution from potential previous invocation.
- Fix: Explicitly declare
- Fix: For
options_page_description(), match method signature of parent class.
- New: Add unit tests.
- Change: Discontinue use of PHP4-style constructor.
- Change: Discontinue use of explicit pass-by-reference for objects.
- Change: Reformat plugin header.
- Change: Add support for language packs:
- Set textdomain using a string instead of a variable.
- Remove .pot file and /lang subdirectory.
- Remove ‘Domain Path’ from plugin header.
- Change: Use explicit path when requiring plugin framework.
- Change: Prevent execution of code if file is directly accessed.
- Change: Minor code reformatting (spacing, bracing, conditional comparison order).
- Change: Minor documentation reformatting (spacing, punctuation).
- Change: Re-license as GPLv2 or later (from X11).
- New: Add ‘License’ and ‘License URI’ header tags to readme.txt and plugin file.
- New: Add LICENSE file.
- New: Add empty index.php to prevent files from being listed if web server has enabled directory listings.
- Change: Note compatibility through WP 4.5+.
- Change: Drop compatibility with version of WP older than 4.1.
- Change: Update donate link.
- Change: Update copyright date (2016).
- New: Add assets to plugin’s Plugin Directory SVN repo.
- Add plugin icon.
- Add banner image.
- Update screenshots.
- Add third screenshot.
- Remove screenshots from plugin package.
- Update plugin framework to version 034
- Fix problem where plugin settings page won’t load for sites with a lot of authors, categories, and/or tags
- Fix correct_paged_offset() to only operate against main query
- By default, disable listing of limits for individual authors, categories, and tags
- Add filter ‘c2c_cpl_enable_all_individual_limits’ to allow enabling limits for all individual authors, categories, and tags (supersedes the specific limits)
- Add filter ‘c2c_cpl_enable_all_individual_author_limits’ to allow enabling limits for individual authors
- Add filter ‘c2c_cpl_enable_all_individual_category_limits’ to allow enabling limits for individual categories
- Add filter ‘c2c_cpl_enable_all_individual_tag_limits’ to allow enabling limits for individual tags
- Remove support for ‘c2c_custom_post_limits’ global
- Note compatibility through WP 3.3+
- Regenerate .pot
- Change plugin description
- Add ‘Domain Path’ directive to top of main plugin file
- Add link to plugin directory page to readme.txt
- Tweak installation instructions in readme.txt
- Update screenshot for WP 3.3
- Add second screenshot
- Update copyright date (2012)
- Add support for different paged (non-first page) limits for each section (each requires separate setting)
- Re-implement/fix display and saving of individual authors/categories/tags limit
- Hide individual author/category/tag limits by default (via JS, so still works for non-JSers)
- Update plugin framework to version 027
- Fix to properly register activation and uninstall hooks
- Save a static version of itself in class variable $instance
- Rename class from ‘CustomPostLimits’ to ‘c2c_CustomPostLimits’
- Remove placeholder settings: individual_authors, individual_categories, and individual_tags
- Remove functions: register_individual_archive_options(), pre_display_option()
- Add functions: save_individual_options(), correct_paged_offset()
- Use get_users() in get_authors() rather than constructing query
- Explicitly declare all functions as public
- Note compatibility through WP 3.2+
- Drop compatibility with versions of WP older than 3.1
- Add more PHPDoc
- Update screenshot
- Regenerate .pot
- Minor tweaks to code formatting (spacing)
- Update copyright date (2011)
- Only output plugin’s admin JS on its own page
- Better localization support
- Store plugin instance in global variable, $c2c_custom_post_limits, to allow for external manipulation
- Re-implementation by extending C2C_Plugin_009, which adds support for:
** Better sanitization of input values
** Offload of core/basic functionality to generic plugin framework
** Additional hooks for various stages/places of plugin operation
** Easier localization support
- Remove docs from top of plugin file (all that and more are in readme.txt)
- Note compatibility with WP 3.0+
- Minor tweaks to code formatting (spacing)
- Add Upgrade Notice section to readme.txt
- Remove trailing whitespace
- Revert post limiting back to hooking ‘pre_option_posts_per_page’ rather than filtering ‘post_limits’ (fixes bug introduced in v2.5)
- Fix bug related to individual author/category/tag limits not applying (the primary intent of the v2.5 release, but needed re-fixing due to reversion)
- Fix bug preventing value of individual limits from appearing on settings page (the value had been saved and used properly, though)
- Add ‘Reset Settings’ button to facilitate resetting all limits configured via the plugin
- Internal: add get_authors(), get_categories(), get_tags() to retrieve and buffer those respective values if actually needed
- Update object’s option buffer after saving changed submitted by user
- Add PHPDoc documentation
- Minor documentation tweaks
- Reverted post limiting method used to filtering ‘post_limits’ again rather than hooking ‘pre_option_posts_per_page’
- Fixed bug related to individual author/category/tag limits not applying
- Changed invocation of plugin’s install function to action hooked in constructor rather than in global space
- Added full support for localization
- Used admin_url() instead of hardcoded admin path
- Removed compatibility with versions of WP older than 2.8
- Noted compatibility with WP 2.9+
- Changed how post limiting is achieved by hooking ‘pre_option_posts_per_page’ rather than filtering ‘post_limits’
- Simplified custom_post_limits()
- Changed permission check to access settings page
- Used plugins_url() instead of hardcoded path
- Removed compatibility with versions of WP older than 2.6
- Noted compatibility with WP2.8
- Began initial effort for localization
- Fixed edge-case bug causing limiting to occur when not appropriate
- Fixed bug with tag names not appearing
- Added ability to specify limit on a per-category, per-author, and per-tag basis
- Added ability to show all posts (i.e no limit, via a limit of -1)
- Added “Settings” link next to “Activate”/”Deactivate” link next to the plugin on the admin plugin listings page
- Tweaked plugin’s admin options page to conform to newer WP 2.7 style
- Extended compatibility to WP 2.7+
- Updated installation instructions, extended description, copyright
- Facilitated translation of some text
- Memoized options
- In admin options page, due to difference b/w WP <2.5 and >2.5, link text for options page is just referred to as “here”
- Prevent post limiting from occurring in the admin listing
- Fixed plugin path problem in recent versions of WP
- Fixed post paging (next_posts_link()/previous_posts_link()) was not taking post limit into account
- Initial release
Copyright & DisclaimerCopyright © 2009-2017 by Scott Reilly (aka coffee2code)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Discussion / Support
Have any questions, comments, or suggestions? Please provide them via the plugin’s WordPress.org support forum. I’ll do my best to reply in a timely fashion and help as best I can.
Unfortunately, I cannot provide guaranteed support, nor do I provide support via any other means.
Was this plugin useful useful to you? Consider giving it a rating. If you’re inclined to give it a poor rating, please first post to the support forum to give me a chance to address or explain the situation.