Custom Posts Per Page] Change the number of posts per page displayed for different page types. Installs an admin/options page to set up the configuration -- also plays with SmallOptions if you have it installed. Author: The Barry Bittwister Cabal Author URI: http://singlenesia.com */ class drt_post { function custom_posts_per_page($query_string) { $query = new WP_Query(); $query->parse_query($query_string); drt_post::init(); $options = get_settings('drt_post_cpp'); if ($query->is_home) { $num = $options['count_home']; $what = $options['what_home']; } elseif ($query->is_day) { $num = $options['count_day'].'&order=DESC'; $what = $options['what_day']; } elseif ($query->is_month) { $num = $options['count_month'].'&order=ASC'; $what = $options['what_month']; } elseif ($query->is_year) { $num = $options['count_year'].'&order=ASC'; $what = $options['what_year']; } elseif ($query->is_author) { $num = $options['count_author']; $what = $options['what_author']; } elseif ($query->is_category) { $num = $options['count_category']; $what = $options['what_category']; } elseif ($query->is_search) { $num = $options['count_search']; $what = $options['what_search']; } if (isset($num)) { if (preg_match("/posts_per_page=/", $query_string)) $query_string = preg_replace("/posts_per_page=[0-9]*/", "posts_per_page=$num", $query_string); else { if ($query_string != '') $query_string .= '&'; $query_string .= "posts_per_page=$num"; } if (preg_match("/what_to_show=/", $query_string)) $query_string = preg_replace("/what_to_show=(posts|days)/", "what_to_show=$what", $query_string); else { if ($query_string != '') $query_string .= '&'; $query_string .= "what_to_show=$what"; } } return $query_string; } function init() { if( !is_array( get_settings('drt_post_cpp') ) ) { $types = array ( "home", "day", "month", "search", "year", "author", "category" ); $numtypes = count( $types ); // We need to initialize // for( $i = 0; $i < $numtypes; $i++ ) { $options["count_".$types[$i]] = 10; $options["what_".$types[$i]] = 'posts'; } add_option('drt_post_cpp', $options); } } function options_page_contents() { $types = array ( "home", "day", "month", "search", "year", "author", "category" ); $numtypes = count( $types ); drt_post::init(); /** Commit changed options if posted **/ if($_SERVER['REQUEST_METHOD'] == 'POST') update_option('drt_post_cpp', $_POST['drt_post_cpp']); echo "
| " size="3" /> | " size="3" /> |
' . __('Options saved.', 'SmallOptions') . '
'; } echo ''; } function admin_menu() { if(class_exists('SmallOptions')) add_action('small_options_page', array('drt_post', 'options_page_contents')); else add_options_page('DRT Custom Posts per Page', 'DRT CPP', 5, basename(__FILE__), array('drt_post', 'options_page')); } } add_filter('query_string', array('drt_post', 'custom_posts_per_page') ); add_action('admin_menu', array('drt_post', 'admin_menu')); ?>