-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
78 lines (69 loc) · 3.12 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
include "./include/layout/header.php";
if (isset($_GET['category'])) {
$categoryId = $_GET['category'];
$posts = $db->prepare("SELECT * FROM tbl_posts WHERE category_id = :id ORDER BY id DESC");
$posts->execute(['id' => $categoryId]);
} else {
$posts = $db->query("SELECT * FROM tbl_posts ORDER BY id DESC");
}
?>
<main>
<?php
include "./include/layout/slider.php";
?>
<!-- Content Section -->
<section class="mt-4">
<div class="row">
<!-- Posts Content -->
<div class="col-lg-8">
<div class="row g-3">
<?php if ($posts->rowCount() > 0) : ?>
<?php foreach ($posts as $item) : ?>
<?php
$categoryId = $item['category_id'];
$postCategory = $db->query("SELECT * FROM tbl_categories WHERE id = $categoryId")->fetch();
?>
<div class="col-sm-6">
<div class="card">
<img src="./uploads/posts/<?= $item['image'] ?>" class="card-img-top" alt="post-image" />
<div class="card-body">
<div class="d-flex justify-content-between">
<h5 class="card-title fw-bold">
<?= $item['title'] ?>
</h5>
<div>
<span class="badge text-bg-secondary"><?= $postCategory['title'] ?></span>
</div>
</div>
<p class="card-text text-secondary pt-3">
<?= substr($item['body'], 0, 500) . "..." ?>
</p>
<div class="d-flex justify-content-between align-items-center">
<a href="single.php?post=<?= $item['id']?>" class="btn btn-sm btn-dark">مشاهده</a>
<p class="fs-7 mb-0">
نویسنده : <?= $item['author'] ?>
</p>
</div>
</div>
</div>
</div>
<?php endforeach ?>
<?php else : ?>
<div class="col">
<div class="alert alert-danger">
مقاله ای یافت نشد ....
</div>
</div>
<?php endif ?>
</div>
</div>
<?php
include "./include/layout/sidebar.php";
?>
</div>
</section>
</main>
<?php
include "./include/layout/footer.php";
?>