Skip to content

Commit 62b8947

Browse files
committed
Adds orderby and order to options page. Removes default values since they're the default anyway
1 parent 8c0759a commit 62b8947

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

include/lcp-options.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
function lcp_settings() { // whitelist options
88
register_setting( 'list_category_posts_group', 'numberposts' );
99
register_setting( 'list_category_posts_group', 'lcp_pagination' );
10+
register_setting( 'list_category_posts_group', 'lcp_orderby' );
11+
register_setting( 'list_category_posts_group', 'lcp_order' );
1012
}
1113

1214
function list_category_posts_menu() {
@@ -56,7 +58,7 @@ function list_category_posts_options() {
5658
<tr valign="top">
5759
<th scope="row">
5860
<label for="lcp_pagination">
59-
<strong><?php _e("Pagination", "list-category-posts"); ?> :</strong>
61+
<strong><?php _e("Pagination", "list-category-posts"); ?> </strong>
6062
</label>
6163
</th>
6264
<td>
@@ -66,6 +68,54 @@ function list_category_posts_options() {
6668
</select>
6769
</td>
6870
</tr>
71+
72+
<tr>
73+
<th scope="row">
74+
<label for="lcp_orderby">
75+
<strong><?php _e("Order by", "list-category-posts"); ?></strong>
76+
</label>
77+
</th>
78+
<td>
79+
<select id="lcp_orderby" name="lcp_orderby" type="text" >
80+
<?php
81+
$lcp_orders = array("date" => __("Date", "list-category-posts"),
82+
"modified" => __("Modified Date", "list-category-posts"),
83+
"title" => __("Post title", "list-category-posts"),
84+
"author" => __("Author", "list-category-posts"),
85+
"rand" => __("Random", "list-category-posts"));
86+
$orderby = get_option('lcp_orderby');
87+
foreach ($lcp_orders as $key=>$value){
88+
$option = '<option value="' . $key . '" ';
89+
if ($orderby == $key){
90+
$option .= ' selected = "selected" ';
91+
}
92+
$option .= '>';
93+
echo $option;
94+
_e($value, 'list-category-posts');
95+
echo '</option>';
96+
}
97+
?>
98+
</select>
99+
</td>
100+
</tr>
101+
102+
<th scope="row">
103+
<label for="lcp_order">
104+
<strong><?php _e("Order", "list-category-posts"); ?></strong>
105+
</label>
106+
</th>
107+
<td>
108+
<select id="lcp_order" name="lcp_order" type="text">
109+
<?php $order = get_option('lcp_order'); ?>
110+
<option value='desc' <?php if($order == 'desc'): echo "selected: selected"; endif;?>>
111+
<?php _e("Descending", 'list-category-posts')?>
112+
</option>
113+
<option value='asc' <?php if($order == 'asc'): echo "selected: selected"; endif; ?>>
114+
<?php _e("Ascending", 'list-category-posts')?>
115+
</option>
116+
</select>
117+
</td>
118+
69119
</tbody>
70120
</table>
71121
<?php submit_button(); ?>

include/lcp-parameters.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ public function get_query_params($params){
2424
'order' => $params['order'],
2525
'offset' => $params['offset']
2626
);
27+
28+
if( get_option('lcp_orderby') && $params['orderby'] === ''){
29+
$orderby = array('orderby' => get_option('lcp_orderby'));
30+
$args = array_merge($args, $orderby);
31+
}
32+
33+
if( get_option('lcp_order') && $params['order'] === ''){
34+
$order = array('order' => get_option('lcp_order'));
35+
$args = array_merge($args, $order);
36+
}
37+
2738
$this->utils = new LcpUtils($params);
2839

2940
// Check posts to exclude

list-category-posts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ static function catlist_func($atts, $content = null) {
4242
$atts = shortcode_atts(array(
4343
'id' => '0',
4444
'name' => '',
45-
'orderby' => 'date',
46-
'order' => 'desc',
45+
'orderby' => '',
46+
'order' => '',
4747
'numberposts' => '',
4848
'date' => 'no',
4949
'date_tag' => '',

0 commit comments

Comments
 (0)