-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory-book.php
More file actions
99 lines (83 loc) · 2.74 KB
/
category-book.php
File metadata and controls
99 lines (83 loc) · 2.74 KB
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
<!-- Default category template (matching with layout-1-4) -->
<!-- header -->
<!-- ====================================== -->
<?php get_header(); ?>
<main role="main">
<!-- intro header -->
<!-- ====================================== -->
<?php
$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;
set_query_var('cat_id', $cat_id);
?>
<?php get_template_part( 'parts/sec-cat-header' ); ?>
<?php wp_reset_query(); ?> <!-- reset -->
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if ($paged == 1){
?>
<!-- editor's choice -->
<!-- ====================================== -->
<?php
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
$list_post_args = array(
'meta_key' => 'top_choice',
'meta_value' => 1,
'numberposts' => 4,
'category' => $cat_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 } // endif paged==1 ?>
<!-- List of posts -->
<!-- ====================================== -->
<?php
// $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// $posts_per_page = 16;
$posts_per_page = get_option('posts_per_page');
$list_post_args = array(
'category' => $cat_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', '');
// pagination
$cat_count = get_category($cat_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-book' ); ?>
<?php get_template_part( 'parts/pagination' ); ?>
</div>
<?php wp_reset_query() ?>
</main>
<!-- footer -->
<!-- ====================================== -->
<?php get_footer(); ?>