This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
page_gifts.php
153 lines (136 loc) · 5.4 KB
/
page_gifts.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/*
Template Name: _gifts
*/
?>
<?php get_header(); ?>
<?php
$prices = array(
//**************************************************
//edit price range
'0-10',
'11-50',
'51-100',
'101-1000',
'1001-2000',
'2001-3000',
'3001-1000000',
//end edit price range
//***************************************************
);
?>
<div class="container">
<div class="row subpage-title text-center">
<h1><?php the_title(); ?></h1>
<?php
$categories = get_categories('exclude=' . implode(',', pinc_blog_cats()) . ', 1');
if($categories){
echo __('Category', 'pinc');
if (!isset($_GET['category']) || $_GET['category'] == '') $active = ' gifts-categories-active';
echo ' <a class="gifts-categories' . $active . '" href="' . get_permalink() . '?category=&price=' . sanitize_text_field($_GET['price']) . '&sort=' . sanitize_text_field($_GET['sort']) . '">' . __('All', 'pinc') . '</a>';
foreach($categories as $category) {
?>
<a class="gifts-categories<?php if ($_GET['category'] == $category->category_nicename) echo ' gifts-categories-active'; ?>" href="<?php echo get_permalink() . '?category=' . $category->category_nicename; ?>&price=<?php echo sanitize_text_field($_GET['price']); ?>&sort=<?php echo sanitize_text_field($_GET['sort']); ?>"><?php echo $category->name; ?></a>
<?php }
} ?>
<div class="clearfix"></div>
<?php _e('Price', 'pinc'); ?>
<?php
if (!isset($_GET['price']) || $_GET['price'] == '') $active_price = ' gifts-categories-active';
echo ' <a class="gifts-categories' . $active_price . '" href="' . get_permalink() . '?category=' . sanitize_text_field($_GET['category']) . '&price=' . '&sort=' . sanitize_text_field($_GET['sort']) . '">' . __('All', 'pinc') . '</a>';
foreach ($prices as $price) {
?>
<a class="gifts-categories<?php if ($_GET['price'] == $price) echo ' gifts-categories-active'; ?>" href="<?php echo get_permalink() . '?category=' . sanitize_text_field($_GET['category']); ?>&price=<?php echo $price; ?>&sort=<?php echo sanitize_text_field($_GET['sort']); ?>"><?php echo $price; ?></a>
<?php } ?>
<div class="clearfix"></div>
<?php _e('Sort by', 'pinc'); ?>
<a class="gifts-categories<?php if (!isset($_GET['sort']) || $_GET['sort'] == '' || $_GET['sort'] == 'recent') echo ' gifts-categories-active'; ?>" href="<?php echo get_permalink() . '?category=' . sanitize_text_field($_GET['category']); ?>&price=<?php echo sanitize_text_field($_GET['price']); ?>&sort=recent"><?php _e('Most recent', 'pinc'); ?></a>
<a class="gifts-categories<?php if ($_GET['sort'] == 'popular') echo ' gifts-categories-active'; ?>" href="<?php echo get_permalink() . '?category=' . sanitize_text_field($_GET['category']); ?>&price=<?php echo sanitize_text_field($_GET['price']); ?>&sort=popular"><?php _e('Most popular', 'pinc'); ?></a>
<a class="gifts-categories<?php if ($_GET['sort'] == 'lowfirst') echo ' gifts-categories-active'; ?>" href="<?php echo get_permalink() . '?category=' . sanitize_text_field($_GET['category']); ?>&price=<?php echo sanitize_text_field($_GET['price']); ?>&sort=lowfirst"><?php _e('Price lowest', 'pinc'); ?></a>
<a class="gifts-categories<?php if ($_GET['sort'] == 'highfirst') echo ' gifts-categories-active'; ?>" href="<?php echo get_permalink() . '?category=' . sanitize_text_field($_GET['category']); ?>&price=<?php echo sanitize_text_field($_GET['price']); ?>&sort=highfirst"><?php _e('Price highest', 'pinc'); ?></a>
<br /></br />
</div>
</div>
<div class="container-fluid">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
switch ($_GET['sort']) {
case "recent":
$order = '';
$orderby = '';
$meta_key = '';
break;
case "popular":
if ('likes' == $popularity = of_get_option('popularity')) {
$order = 'desc';
$orderby = 'meta_value_num';
$meta_key = '_Likes Count';
} else if ($popularity == 'repins') {
$order = 'desc';
$orderby = 'meta_value_num';
$meta_key = '_Repin Count';
} else if ($popularity == 'comments') {
$order = 'desc';
$orderby = 'comment_count';
$meta_key = '';
} else {
$order = 'desc';
$orderby = 'comment_count';
$meta_key = '';
}
break;
case "lowfirst":
$order = 'asc';
$orderby = 'meta_value_num';
$meta_key = '_Price';
break;
case "highfirst":
$order = 'desc';
$orderby = 'meta_value_num';
$meta_key = '_Price';
break;
default:
$order = '';
$orderby = '';
$meta_key = '';
}
if (isset($_GET['price']) && $_GET['price'] != '') {
$price = explode('-', sanitize_text_field($_GET['price']));
$args = array(
'category_name' => sanitize_text_field($_GET['category']),
'meta_query' => array(
array(
'key' => '_Price',
'value' => $price,
'type' => 'numeric',
'compare' => 'BETWEEN'
)
),
'orderby' => $orderby,
'meta_key' => $meta_key,
'order' => $order,
'paged' => $paged
);
} else {
$args = array(
'category_name' => sanitize_text_field($_GET['category']),
'meta_query' => array(
array(
'key' => '_Price',
'compare' => 'EXISTS'
)
),
'orderby' => $orderby,
'meta_key' => $meta_key,
'order' => $order,
'paged' => $paged
);
}
if ($orderby == 'meta_value_num')
add_filter('posts_orderby', 'pinc_meta_value_num_orderby');
query_posts($args);
if ($orderby == 'meta_value_num')
remove_filter('posts_orderby', 'pinc_meta_value_num_orderby');
get_template_part('index', 'masonry');
get_footer();
?>