[wp-hackers] Posts on archives / categories

Andrew Bevitt me at andrewbevitt.com
Fri May 18 14:42:40 GMT 2007


Hi All,

I am wondering what people think about the attached patch.

Essentially it adds a single option posts_per_archive_page which
provides a separate limit for the number of posts that should be
displayed on archive and category pages. Separate to the
posts_per_page which, currently, limits the number of posts displayed
on any page. This can also be achieved with the Custom Query Search
plugin, however CQS is no longer actively supported, so I suggest this
option be added to Wordpress.

Thoughts?

Patch will apply against current trunk.

Andrew
-------------- next part --------------
--- wp-includes/query.php.orig	2007-05-19 00:38:00.000000000 +1000
+++ wp-includes/query.php	2007-05-19 00:40:11.000000000 +1000
@@ -682,8 +682,13 @@
 		if ( !isset($q['post_type']) )
 			$q['post_type'] = 'post';
 		$post_type = $q['post_type'];
-		if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 )
-			$q['posts_per_page'] = get_option('posts_per_page');
+		if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 ) {
+			if ($this->is_archive || $this->is_search || $this->is_category) {
+				$q['posts_per_page'] = get_option('posts_per_archive_page');
+			} else {
+				$q['posts_per_page'] = get_option('posts_per_page');
+			}
+		}
 		if ( isset($q['showposts']) && $q['showposts'] ) {
 			$q['showposts'] = (int) $q['showposts'];
 			$q['posts_per_page'] = $q['showposts'];
--- wp-admin/options.php.orig	2007-05-19 00:39:24.000000000 +1000
+++ wp-admin/options.php	2007-05-19 00:40:11.000000000 +1000
@@ -27,6 +27,7 @@
 
 		case 'posts_per_page':
 		case 'posts_per_rss':
+		case 'posts_per_archive_page':
 			$value = stripslashes($value);
 			$value = (int) $value;
 			if ( empty($value) ) $value = 1;
--- wp-admin/options-reading.php.orig	2007-05-19 00:39:43.000000000 +1000
+++ wp-admin/options-reading.php	2007-05-19 00:40:11.000000000 +1000
@@ -55,6 +55,12 @@
 <input name="posts_per_page" type="text" id="posts_per_page" value="<?php form_option('posts_per_page'); ?>" size="3" /> <?php _e('posts') ?>
 </td> 
 </tr> 
+<tr valign="top">
+<th width="33%" scope="row"><?php _e('Show on archives:') ?></th>
+<td>
+<input name="posts_per_archive_page" type="text" id="posts_per_archive_page" value="<?php form_option('posts_per_archive_page'); ?>" size="3" /> <?php _e('posts'); ?>
+</td>
+</tr>
 </table> 
 </fieldset> 
 
@@ -88,9 +94,9 @@
 </p>
 <p class="submit">
 <input type="hidden" name="action" value="update" /> 
-<input type="hidden" name="page_options" value="posts_per_page,posts_per_rss,rss_use_excerpt,blog_charset,gzipcompression,show_on_front,page_on_front,page_for_posts" /> 
+<input type="hidden" name="page_options" value="posts_per_page,posts_per_archive_page,posts_per_rss,rss_use_excerpt,blog_charset,gzipcompression,show_on_front,page_on_front,page_for_posts" /> 
 <input type="submit" name="Submit" value="<?php _e('Update Options &raquo;') ?>" /> 
 </p> 
 </form> 
 </div> 
-<?php include('./admin-footer.php'); ?>
\ No newline at end of file
+<?php include('./admin-footer.php'); ?>


More information about the wp-hackers mailing list