-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag.php
More file actions
118 lines (102 loc) · 4.36 KB
/
tag.php
File metadata and controls
118 lines (102 loc) · 4.36 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
require_once 'include/db.inc.php';
require_once 'include/class_autoloader.inc.php';
require_once 'include/config.inc.php';
$tag_id = (int) $_GET['tag_id'];
if (!$tag_id) {
header("Location:".$_SERVER['HTTP_REFERER']);
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php require_once 'partials/__head.php'; ?>
<title>View cateogry |
<?= SITE_NAME ?>
</title>
</head>
<body>
<!-- Navigation -->
<?php require_once 'partials/__nav.php'; ?>
<!-- Page Header -->
<?php require_once 'partials/__page_header.php'; ?>
<!-- Main Content -->
<div class="container px-4 px-lg-5">
<div class="row gx-4 gx-lg-5 justify-content-center">
<div class="col-md-10 col-lg-8 col-xl-7">
<?php
try {
$blog = new Blog;
$user = new User;
$allPosts = $blog->getAllTagPosts($tag_id);
if (!empty($allPosts['posts'])) {
foreach ($allPosts['posts'] as $post) {
?>
<div class="post-preview">
<a href="post.php?slug=<?= $post['slug'] ?>#disqus_thread">
<h2 class="post-title">
<?= $post['title']; ?>
</h2>
<h3 class="post-subtitle">
<?php echo substr($post['excerpt'], 0, 150) ?>
</h3>
</a>
<p class="post-meta">
Posted by
<a href="user.php?slug=<?= $user->getUserDetails($post['user_id'])[0]['slug'] ?>">
<?php
if (!empty($user->getUserDetails($post['user_id']))) {
echo $user->getUserDetails($post['user_id'])[0]['name'];
}
?>
</a>
on
<?php
$timeago = new get_timeago;
echo $timeago->timeago($post['created_at']); ?>
</p>
</div>
<?php
}
if (count($allPosts) > 0) {
$pages = $blog->getAllTagPosts($tag_id)['pages'];
?>
<nav aria-label="Page navigation example">
<ul class="pagination">
<?php
for ($i = 1; $i <= $pages; $i++) {
$perPage = $blog->getAllTagPosts($tag_id)['per-page'];
?>
<li class="page-item"> <a class="page-link"
href="?tag_id=<?=$tag_id; ?>&&page=<?php echo $i; ?>&&per-page=<?php echo $perPage ?>"><?= $i ?></a>
</li>
<?php
}
?>
</ul>
</nav>
<?php
}
} else {
echo '<h3 class="noPost">No posts available.</h3>';
}
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
<!-- Pager -->
<div class="d-flex justify-content-end mb-4">
<a class="btn btn-primary text-uppercase" href="#!">Older Posts →</a>
</div>
</div>
</div>
</div>
<!-- Footer -->
<?php require_once 'partials/__footer.php'; ?>
<!-- Bootstrap core JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core theme JS -->
<script src="js/scripts.js"></script>
</body>
</html>