-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.php
61 lines (55 loc) · 2.52 KB
/
category.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!-- header -->
<?php
include 'includes/header.php';
?>
<body>
<!-- Responsive navbar-->
<?php include 'includes/navbar.php' ?>
<!-- Page title -->
<?php include 'includes/title.php' ?>
<!-- Page content-->
<div class="container">
<div class="row">
<!-- Page content-->
<!-- Blog entries-->
<div class="col-lg-8">
<?php
if (isset($_GET['cat_id'])) {
$cat_id = mysqli_real_escape_string($data, $_GET['cat_id']);
}
$query = "SELECT * FROM posts WHERE post_category_id = $cat_id AND post_status = 'published'"; // query string for the db
$select_posts = mysqli_query($data, $query); //import db data for posts
foreach ($select_posts as $post) { //for each of the db posts go through them
// values to be passed to html
$p_id = $post['post_id'];
$p_category_id = $post['post_category_id'];
$p_title = $post['post_title'];
$p_author = $post['post_author'];
$p_date = $post['post_date'];
$p_image = $post['post_image'];
$p_content = $post['post_content'];
$p_tags = $post['post_tags'];
$p_comments_count = $post['post_comments_count'];
$p_status = $post['post_status'];
?>
<!-- Featured blog post appended with php dynamicaly generated content-->
<div class="card mb-4">
<a href="post.php?p_id=<?php echo $p_id; ?>"><img class="card-img-top" src="img/<?php echo $p_image; ?>" alt="" /></a>
<div class="card-body">
<div class="small text-muted"><?php echo $p_date; ?> By <?php echo $p_author; ?></div>
<h2 class="card-title"><?php echo $p_title; ?></h2>
<p class="card-text"><?php echo substr($p_content, 0, 150) . '...'; ?></p>
<a class="btn btn-outline-secondary btn-sm float-end" href="post.php?p_id=<?php echo $p_id; ?>">Read more →</a>
</div>
</div>
<?php
}
?>
</div>
<!-- sidebar -->
<?php include 'includes/sidebar.php' ?>
</div>
</div>
</div>
<!-- footer -->
<?php include 'includes/footer.php' ?>