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_popular.php
92 lines (85 loc) · 2.91 KB
/
page_popular.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
<?php
/*
Template Name: _popular
*/
?>
<?php get_header(); ?>
<div class="container">
<div class="row subpage-title">
<h1><?php _e('Popular', 'pinc'); ?></h1>
<?php
$categories = get_categories('exclude=' . implode(',', pinc_blog_cats()) . ', 1');
if ($categories){
echo '<div class="text-center">' . __('Category', 'pinc');
if (!isset($_GET['category'])) $active = ' popular-categories-active';
echo ' <a class="popular-categories' . $active . '" href="' . get_permalink() . '">' . __('All', 'pinc') . '</a>';
foreach($categories as $category) {
?>
<a class="popular-categories<?php if ($_GET['category'] == $category->category_nicename) echo ' popular-categories-active'; ?>" href="<?php echo get_permalink(); ?>?category=<?php echo $category->category_nicename; ?>"><?php echo $category->name; ?></a>
<?php }
echo '</div><br />';
} ?>
</div>
</div>
<div class="container-fluid">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
function filter_where($where = '') {
$duration = '-' . of_get_option('popularity_duration') . ' days';
$where .= " AND post_date > '" . date('Y-m-d', strtotime($duration)) . "'";
if (of_get_option('popularity') == 'comments') {
$where .= ' AND comment_count != 0';
}
return $where;
}
if ('likes' == $popularity = of_get_option('popularity')) {
$args = array(
'meta_key' => '_Likes Count',
'meta_compare' => '>',
'meta_value' => '0',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'category_name' => sanitize_text_field($_GET['category']),
'paged' => $paged
);
add_filter('posts_where', 'filter_where');
add_filter('posts_orderby', 'pinc_meta_value_num_orderby');
query_posts($args);
remove_filter('posts_where', 'filter_where');
remove_filter('posts_orderby', 'pinc_meta_value_num_orderby');
} else if ($popularity == 'repins') {
$args = array(
'meta_key' => '_Repin Count',
'meta_compare' => '>',
'meta_value' => '0',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'category_name' => sanitize_text_field($_GET['category']),
'paged' => $paged
);
add_filter('posts_where', 'filter_where');
add_filter('posts_orderby', 'pinc_meta_value_num_orderby');
query_posts($args);
remove_filter('posts_where', 'filter_where');
remove_filter('posts_orderby', 'pinc_meta_value_num_orderby');
} else if ($popularity == 'comments') {
$args = array(
'orderby' => 'comment_count',
'category_name' => sanitize_text_field($_GET['category']),
'paged' => $paged
);
add_filter('posts_where', 'filter_where');
add_filter('posts_orderby', 'pinc_comments_orderby');
query_posts($args);
remove_filter('posts_where', 'filter_where');
remove_filter('posts_orderby', 'pinc_comments_orderby');
} else {
$args = array(
'category_name' => sanitize_text_field($_GET['category']),
'paged' => $paged
);
query_posts($args);
}
get_template_part('index', 'masonry');
get_footer();
?>