Change Admin Pagination on Posts, Pages and Comments

One or the other users in the backend of WordPress find it quite disturbing that not more than 20 articles, pages and comments per page gets listed. Especially if you work with many tables and you have a fast connection, then an increased number of listed articles, pages, comments is useful. How to adapt and with a little CSS getting the best presentation I will show now, here are some tips.

As of WordPress version 2.8

With WordPress 2.8 comes a new value in the user’s options for each page in the backend. This allows each user to extend the number of listed pages, articles and comments per page. If you like to solve it also in advance of WordPress 2.8, then the following syntax helps.

posts_per_page

Alternative Plugin

You should embed the syntax in a Plugin.
I am purposely not providing a Plugin, because the support of my existing solutions is already overwhelming. So it is rather as a basis for people who want to start here and as a memory for me when I need it again.

Some comments I have directly written down in the source code, so it is understandable. Also I do upload a CSS file, the content can be found at the end, which changes the design a little bit and create a better overview of the large number of entries.

posts_per_page2

// value for posts
define( 'FB_CAP_PER_POST', 100 );
// value for pages
define( 'FB_CAP_PER_PAGE', 100 );
// value for comments
define( 'FB_CAP_PER_COMMENT', 100 );

// only in admin area
if ( is_admin() ) {
	global $pagenow;
	
	if ( $pagenow == 'edit-pages.php' ) {
		add_filter( 'manage_pages_query', 'page_ChangeAdminPagination' );
		add_action( 'admin_print_styles', 'AddMyStylesheet' );
	}
	if ( $pagenow == 'edit.php' ) {
		add_action( 'admin_head', 'post_ChangeAdminPagination' );
		add_action( 'admin_print_styles', 'AddMyStylesheet' );
	}
	if ( $pagenow == 'edit-comments.php' )
		add_filter( 'comments_per_page', 'comment_ChangeAdminPagination' );
}
	
function post_ChangeAdminPagination() {
	global $wp_query;
	
	if ( $wp_query->query_vars[s] == '' ) {
		$per_post = (int) FB_CAP_PER_POST;
		$wp_query->query( 'showposts=' . $per_post );
	}
}

function page_ChangeAdminPagination($query) {
	global $per_page;
	
	$per_page = (int) FB_CAP_PER_PAGE;
	//$query['posts_per_page'] = $per_page;
	$query['posts_per_archive_page'] = $per_page;
	
	return $query;
}

function comment_ChangeAdminPagination($count) {

	$per_comment = (int) FB_CAP_PER_COMMENT;
	
	return $per_comment;
}

function AddMyStylesheet() {
	
		$myStyleFile = WP_PLUGIN_URL . '/change_admin_pagination/css/style.css';
		wp_register_style( 'change_admin_pagination', $myStyleFile );
		wp_enqueue_style( 'change_admin_pagination');
}

The following content is intended only to that area for editing the page or next to the entry contribution is shown. Thus, the line is smaller and has more entries available to view.

/**
 * style for smaller tables in admin of WordPress
 * @author Frank Bültge
 * @date 01.04.2009 20:51:59
 */
.post-title strong {
	float: left;
}

.row-actions {
	float: left;
	margin-left: 1% !important;
}

.check-column, tr td {
	padding-bottom: 0 !important;
}


.column-date {
	width: 15% !important;
}

td.date {
	font-size: .6em;
}

td.date abbr {
	float: right;
}

Posted

in

,

by

Comments

7 responses to “Change Admin Pagination on Posts, Pages and Comments”

  1. Christopher Ross Avatar

    Very cool Frank!

    In the past I’ve noticed that the admin tool is a big of a resource pig compared to the front (especially when using a cache script), I’m curious if this hack will help relieve some of the strain it’s putting on my server.

  2. Alex Vorn Avatar

    Thanks! Maybe I will use these on my future theme 🙂

  3. Frank Avatar

    I have updated the function for posts – this is better for filter and pagination. I have seen problems with the first function on WordPress 2.7; I write everything on the nightly build.

    I hope you enjoy:

    function post_ChangeAdminPagination($default_limit) {
    	global $wp_query;
    	
    	// default WP Filter
    	// $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" )
    	
    	if ( !$default_limit )
    		return $default_limit;
    	
    	// explode values
    	// default: LIMIT 0, 15
    	list( $start, $limit ) = explode(',', $default_limit, 2);
    	
    	$limit = (int) FB_CAP_PER_POST;
    	
    	if ( is_paged() ) {
    		$start = $wp_query->query_vars['offset'];
    		$paged = $wp_query->query_vars['paged'];
    		
    		$start = ($paged - 1) * $limit;
    		
    		$start = 'LIMIT ' . $start;
    	}
    	
    	$wp_query->query_vars['posts_per_page'] = $limit;
    	
    	return $start . ', ' . $limit;
    }
    

    Best regards Frank

  4. link2caro Avatar
    link2caro

    For 2.8, filters are better ?

    [source lang=php]
    add_filter( ‘edit_posts_per_page’, ‘cr_posts_per_page’ );
    add_filter( ‘edit_pages_per_page’, ‘cr_pages_per_page’ );
    [/source]

  5. Frank Avatar

    Yes, in 2.8 is this an user-option get_user_option('edit_pages_per_page') and you can set via filter.

  6. […] Tip: Change Pagination in WordPress Admin Panel Written by Stefan Vervoort on April 26, 2009 Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic.Powered by WP Greet BoxWhen I am looking to moderate some comments or simply browse my posts in my WP-admin section, I find it pretty annoying that WordPress only shows 20 items. There are more people that don’t like this and that’s why WP Engineer build a solution. […]

  7. […] Bueltge.de // WPengineer.com […]