-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory-tool.php
113 lines (98 loc) · 3.12 KB
/
category-tool.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
<?php get_header(); ?>
<main role="main">
<?php
$taxonomy_id = get_queried_object()->term_id;
set_query_var('cat_id', $taxonomy_id);
?>
<?php get_template_part( 'parts/sec-cat-header' ); ?>
<?php wp_reset_query(); ?> <!-- reset -->
<?php // get_template_part( 'parts/subscribe-bar' ); ?>
<?php
// editor's choice
// ======================================
set_query_var('typeTitle', 'small');
set_query_var('customTitle', 'Tuyển chọn');
set_query_var('customURL', get_site_url().'/choice');
set_query_var('customIcon', 'icon-star-circled');
set_query_var('customSecClass', 'sec-choice-cat section-border-bottom');
// list of posts
if (is_category()){
$list_post_args = array(
'meta_key' => 'top_choice',
'meta_value' => 1,
'numberposts' => 4,
'category' => $taxonomy_id,
'orderby' => 'rand',
'post_status' => 'publish'
);
}elseif (is_tag()){
$list_post_args = array(
'meta_key' => 'top_choice',
'meta_value' => 1,
'numberposts' => 4,
'tag_id' => $taxonomy_id,
'orderby' => 'rand',
'post_status' => 'publish'
);
}
$list_posts = get_posts($list_post_args);
set_query_var('list_posts', $list_posts);
?>
<?php get_template_part( 'parts/cat-layout-photo-behind' ); ?>
<?php wp_reset_query(); // reset ?>
<?php
// List of posts
// ======================================
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$posts_per_page = get_option('posts_per_page');
// list of posts
if (is_category()){
$list_post_args = array(
'category' => $taxonomy_id,
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'post_status' => 'publish'
);
}elseif (is_tag()){
$list_post_args = array(
'tag_id' => $taxonomy_id,
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'post_status' => 'publish'
);
}
$list_posts = get_posts($list_post_args);
set_query_var('typeTitle', '');
set_query_var('list_posts', $list_posts);
set_query_var('customSecClass', '');
if (!is_category()){
set_query_var('display_category', true);
}
// pagination
if (is_category()){
$cat_count = get_category($taxonomy_id);
}elseif (is_tag()){
$cat_count = get_tag($taxonomy_id);
}
$found_posts = $cat_count->count;
$number_of_pages = ceil($found_posts / $posts_per_page);
$big = 999999999; // need an unlikely integer
$pag_arg = array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'prev_text' => __('⟨'),
'next_text' => __('⟩'),
'current' => max( 1, get_query_var('paged') ),
'total' => $number_of_pages
);
// for pagination
set_query_var('pag_arg', $pag_arg);
set_query_var('number_of_pages', $number_of_pages);
?>
<div class="all-posts">
<?php get_template_part( 'parts/cat-layout-tool' ); ?>
<?php get_template_part( 'parts/pagination' ); ?>
</div>
<?php wp_reset_query() ?>
</main>
<?php get_footer(); ?>