-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposts_by_category.php
More file actions
92 lines (71 loc) · 3.17 KB
/
posts_by_category.php
File metadata and controls
92 lines (71 loc) · 3.17 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
<?php
require_once('assets/src/db_connect.php');
require_once('assets/src/functions.php');
if (isset($_GET['current_page']) && !empty($_GET['current_page'])) {
$current_page = (int) escape_string(trim($_GET['current_page']));
} else {
$current_page = 1;
}
if (isset($_GET['post_category_id']) && !empty($_GET['post_category_id'])) {
$post_category_id = (int) escape_string(trim($_GET['post_category_id']));
} else {
$post_category_id = 0;
}
$per_page = 6;
$q = '';
if (isset($_GET["q"]) && !empty($_GET['q'])) {
$q = escape_string(trim($_GET["q"]));
}
$total_count = count_posts_by_category_id($q, $post_category_id);
$offset = offset($current_page, $per_page);
$total_pages = total_pages($total_count, $per_page);
?>
<?php require_once('assets/layouts/public_header.php'); ?>
<?php $result = get_posts_by_category_id($q, $post_category_id, $per_page, $offset); ?>
<?php if ($result->num_rows > 0) { ?>
<div class="container">
<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 text-center">
<h2>Posts</h2>
</div>
</div>
<div class="container">
<div class="row">
<?php while ($row = $result->fetch_assoc()) { ?>
<div class="col-lg-8 col-md-8 col-sm-6 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title text-center"><?php echo htmlentities($row['title']); ?></h3>
</div>
<div class="panel-body"><?php echo htmlentities($row['body']); ?></div>
</div>
</div>
<?php } ?>
</div>
<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12 text-center">
<ul class="pagination">
<?php
if ($total_pages > 1) {
if($current_page - 1 >= 1) {
$per_page = $current_page - 1;
echo "<li><a href='posts_by_category.php?q=". urlencode($q) . "¤t_page={$per_page}&post_category_id={$post_category_id}'>«</a></li>";
}
for($i=1; $i <= $total_pages; $i++) {
if ($i == $current_page) {
echo "<li class='active'><a href='posts_by_category.php?q=". urlencode($q) . "¤t_page={$i}&post_category_id={$post_category_id}'>{$i}</a></li>";
} else {
echo "<li><a href='posts_by_category.php?q=". urlencode($q) . "¤t_page={$i}&post_category_id={$post_category_id}'>{$i}</a></li>";
}
}
if(($current_page + 1) <= $total_pages) {
$next_page = $current_page + 1;
echo "<li><a href='posts_by_category.php?q=". urlencode($q) . "¤t_page={$next_page}&post_category_id={$post_category_id}'>»</a></li>";
}
}
?>
</ul>
</div>
</div>
<?php } else { ?>
<h2 class="text-center">No record was found.</h2>
<?php } ?>
<?php require_once('assets/layouts/public_footer.php'); ?>