-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcbnet-different-posts-per-page.php
207 lines (99 loc) · 3.37 KB
/
cbnet-different-posts-per-page.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/*
* Plugin Name: cbnet Different Posts Per Page
* Plugin URI: http://www.chipbennett.net/wordpress/plugins/cbnet-different-posts-per-page/
* Description: Customize the number of posts, orderby, and order parameters for all index pages (blog/home, search, category, tag, taxonomy, author, date, and archive index).
* Version: 2.2
* Author: chipbennett
* Author URI: http://www.chipbennett.net/
*
* License: GNU General Public License, v2 (or newer)
* License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* 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.
*
* Version 2.0 and later of this Plugin: Copyright (C) 2012 Chip Bennett,
* Released under the GNU General Public License, version 2.0 (or newer)
*
* Previous versions of this Plugin were derived from MaxBlogPress Different Posts Per Page plugin, version 1.7.6,
* Copyright (C) 2007 www.maxblogpress.com, released under the GNU General Public License.
*/
/**
* Load Plugin textdomain
*/
function cbnetdppp_load_textdomain() {
load_plugin_textdomain( 'cbnetdppp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
// Load Plugin textdomain
add_action( 'plugins_loaded', 'cbnetdppp_load_textdomain' );
/**
* Bootstrap Plugin Options
*/
include( plugin_dir_path( __FILE__ ) . 'options.php' );
/**
* Globalize the variable that holds the Plugin Options
*
* @global array $cbnetdppp_options holds Plugin options
*/
global $cbnetdppp_options;
$cbnetdppp_options = cbnetdppp_get_options();
/**
* Filter pre_get_posts
*/
function cbnetdppp_filter_pre_get_posts( $query ) {
// Globalize Plugin options
global $cbnetdppp_options;
// Only modify the main query
if ( $query->is_main_query() ) {
$context = '';
// Search results index
if ( is_search() ) {
$context = 'search';
}
// Blog posts index
else if ( is_home() ) {
$context = 'blog';
}
// Category archive index
else if ( is_category() ) {
$context = 'category';
}
// Tag archive index
else if ( is_tag() ) {
$context = 'tag';
}
// Taxonomy archive index
else if ( is_tax() ) {
$context = 'taxonomy';
}
// Author archive index
else if ( is_author() ) {
$context = 'author';
}
// Date archive index
else if ( is_date() ) {
$context = 'date';
}
// Archive index
else if ( is_archive() ) {
$context = 'archive';
}
// Modify the query variables according to context
if ( '' != $context ) {
$query->set( 'posts_per_page', $cbnetdppp_options[$context . '_posts_per_page'] );
$query->set( 'orderby', $cbnetdppp_options[$context . '_orderby'] );
$query->set( 'order', $cbnetdppp_options[$context . '_order'] );
}
}
return $query;
}
add_action( 'pre_get_posts', 'cbnetdppp_filter_pre_get_posts' );
?>