-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblog.php
More file actions
137 lines (117 loc) · 4.71 KB
/
blog.php
File metadata and controls
137 lines (117 loc) · 4.71 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
include "core.php";
head();
if ($settings['sidebar_position'] == 'Left') {
sidebar();
}
?>
<div class="col-md-8 mb-3">
<div class="card">
<div class="card-header"><i class="far fa-file-alt"></i> Blog Posts</div>
<div class="card-body">
<?php
$postsperpage = 8;
$pageNum = 1;
if (isset($_GET['page'])) {
$pageNum = $_GET['page'];
}
if (!is_numeric($pageNum)) {
echo '<meta http-equiv="refresh" content="0; url=blog">';
exit();
}
$rows = ($pageNum - 1) * $postsperpage;
$run = mysqli_query($connect, "SELECT * FROM `posts` WHERE active='Yes' ORDER BY id DESC LIMIT $rows, $postsperpage");
$count = mysqli_num_rows($run);
if ($count <= 0) {
echo '<div class="alert alert-info">There are no published posts</div>';
} else {
while ($row = mysqli_fetch_assoc($run)) {
$image = "";
if($row['image'] != "") {
$image = '<img src="' . $row['image'] . '" alt="' . $row['title'] . '" class="rounded-start" width="100%" height="100%">';
} else {
$image = '<svg class="bd-placeholder-img rounded-start" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Thumbnail" preserveAspectRatio="xMidYMid slice" focusable="false">
<title>No Image</title><rect width="100%" height="100%" fill="#55595c"/>
<text x="37%" y="50%" fill="#eceeef" dy=".3em">No Image</text></svg>';
}
echo '
<div class="card shadow-sm mb-3">
<div class="row g-0">
<div class="col-md-4">
<a href="post?name=' . $row['slug'] . '">
'. $image .'
</a>
</div>
<div class="col-md-8">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center row">
<div class="col-md-9">
<a href="post?name=' . $row['slug'] . '">
<h5 class="card-title">' . $row['title'] . '</h5>
</a>
</div>
<div class="col-md-3">
<a href="category?name=' . post_categoryslug($row['category_id']) . '">
<span class="badge bg-primary float-end">' . post_category($row['category_id']) . '</span>
</a>
</div>
</div>
<div class="d-flex justify-content-between align-items-center mb-3">
<small>
Posted by <b><i><i class="fas fa-user"></i> ' . post_author($row['author_id']) . '</i></b>
on <b><i><i class="far fa-calendar-alt"></i> ' . date($settings['date_format'], strtotime($row['date'])) . ', ' . $row['time'] . '</i></b>
</small>
<small class="float-end"><i class="fas fa-comments"></i>
<a href="post?name=' . $row['slug'] . '#comments" class="blog-comments"><b>' . post_commentscount($row['id']) . '</b></a>
</small>
</div>
<p class="card-text">' . short_text(strip_tags(html_entity_decode($row['content'])), 200) . '</p>
</div>
</div>
</div>
</div>
';
}
$query = "SELECT COUNT(id) AS numrows FROM posts WHERE active='Yes'";
$result = mysqli_query($connect, $query);
$row = mysqli_fetch_array($result);
$numrows = $row['numrows'];
$maxPage = ceil($numrows / $postsperpage);
$pagenums = '';
echo '<center>';
for ($page = 1; $page <= $maxPage; $page++) {
if ($page == $pageNum) {
$pagenums .= "<a href='?page=$page' class='btn btn-primary'>$page</a> ";
} else {
$pagenums .= "<a href=\"?page=$page\" class='btn btn-default'>$page</a> ";
}
}
if ($pageNum > 1) {
$page = $pageNum - 1;
$previous = "<a href=\"?page=$page\" class='btn btn-default'><i class='fa fa-arrow-left'></i> Previous</a> ";
$first = "<a href=\"?page=1\" class='btn btn-default'>First</a> ";
} else {
$previous = ' ';
$first = ' ';
}
if ($pageNum < $maxPage) {
$page = $pageNum + 1;
$next = "<a href=\"?page=$page\" class='btn btn-default'><i class='fa fa-arrow-right'></i> Next</a> ";
$last = "<a href=\"?page=$maxPage\" class='btn btn-default'>Last</a> ";
} else {
$next = ' ';
$last = ' ';
}
echo $first . $previous . $pagenums . $next . $last;
echo '</center>';
}
?>
</div>
</div>
</div>
<?php
if ($settings['sidebar_position'] == 'Right') {
sidebar();
}
footer();
?>