-
Notifications
You must be signed in to change notification settings - Fork 0
/
posts.php
43 lines (34 loc) · 1.21 KB
/
posts.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
<?php include "includes/header.php";?>
<?php
//Create database object
$db = new Database();
if(isset($_GET['category'])){
$category = $_GET['category'];
//create query
$query = "SELECT * FROM `posts` WHERE category=".$category." ORDER BY id DESC";
//run query
$posts = $db->select($query);
}else{
//create query
$query = "SELECT * FROM `posts` ORDER BY id DESC";
//run query
$posts = $db->select($query);
}
//create query
$query = "SELECT * FROM `categories`";
//run query
$categories = $db->select($query);
?>
<?php if($posts):?>
<?php while($row = $posts->fetch_assoc()) :?>
<div class="blog-post">
<h2 class="blog-post-title"><?php echo $row['title'];?></h2>
<p class="blog-post-meta"><?php echo formatDate($row['date']);?> by <a href="#"><?php echo $row['author'];?></a></p>
<?php echo shortenText($row['body']);?>
<a class ="readmore" href="post.php?id=<?php echo urlencode($row['id']);?>">Read More</a>
</div><!-- /.blog-post -->
<?php endwhile;?>
<?php else:?>
<p>There are no posts yet</p>
<?php endif;?>
<?php include "includes/footer.php";?>