Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
139 lines (119 loc) · 5.3 KB
/
Copy pathindex.php
File metadata and controls
139 lines (119 loc) · 5.3 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
138
139
<?php
include 'partial/header.php';
//fetech featured post from the database
$featured_sql = "SELECT * FROM post WHERE is_featured = 1";
$featured_result = mysqli_query($conn, $featured_sql);
$featured_post = mysqli_fetch_assoc($featured_result);
//fetech post from the database
$post_sql = "SELECT * FROM post WHERE is_featured = 0 ORDER BY date_time DESC LIMIT 12";
$post_result = mysqli_query($conn, $post_sql);
?>
<?php if (mysqli_num_rows($featured_result) == 1 ) : ?>
<section class="featured">
<div class="container featured_container">
<div class="post_thumbnail">
<img src="./images/<?= $featured_post['thumbnail'] ?>">
</div>
<div class="post_info">
<!--fetech categorie from the database -->
<?php
$category_id = $featured_post['category_id'];
$sql = "SELECT * FROM category WHERE id = $category_id";
$result = mysqli_query($conn, $sql);
$category = mysqli_fetch_assoc($result);
?>
<a href="category-post.php" class="category_button"><?=$category['title']?></a>
<h2 class="post_title">
<a href="post.php?id=<?=$featured_post['id']?>"><?= $featured_post['title'] ?> </a>
</h2>
<p class="post_body" >
<?= substr($featured_post['body'], 0, 200) ?>...
</p>
<!-- fetch user from the database -->
<div class="post_author">
<?php
$author_id = $featured_post['author_id'];
$sql = "SELECT * FROM users WHERE id = $author_id";
$result = mysqli_query($conn, $sql);
$author = mysqli_fetch_assoc($result);
?>
<div class="post_author_avatar">
<img src="./images/<?=$author['avatar']?>">
</div>
<div class="post_author-info">
<h5><?= "{$author['first_name']} {$author['last_name']}"?></h5>
<small>
<?=date("M d, Y - H:i", strtotime($featured_post['date_time']))?>
</small>
</div>
</div>
</div>
</div>
</section>
<?php endif;?>
<!--End Feature-->
<?php if(mysqli_num_rows($post_result) > 0) : ?>
<section class="posts">
<div class="container posts_container">
<!-- loop through the list of posts -->
<?php while($post = mysqli_fetch_assoc($post_result)) :?>
<article class="post">
<div class="post_thumbnail">
<img src="./images/<?= $post['thumbnail'] ?>">
</div>
<div class="post_info">
<!-- fetch categorie from the database -->
<?php
$category_id = $post['category_id'];
$sql = "SELECT * FROM category WHERE id = $category_id";
$result = mysqli_query($conn, $sql);
$category = mysqli_fetch_assoc($result);
?>
<a href="category-post.php" class="category_button"><?=$category['title']?></a>
<h3 class="post_title">
<a href="post.php?id=<?=$post['id']?>"><?= $post['title']?></a>
</h3>
<p class="post_body">
<?= substr($post['body'], 0, 200) ?>...
</p>
<!-- fetch user from the database -->
<div class="post_author">
<?php
$author_id = $post['author_id'];
$sql = "SELECT * FROM users WHERE id = $author_id";
$result = mysqli_query($conn, $sql);
$author = mysqli_fetch_assoc($result);
?>
<div class="post_author_avatar">
<img src="./images/<?=$author['avatar']?>">
</div>
<div class="post_author-info">
<h5><?= "{$author['first_name']} {$author['last_name']}"?></h5>
<small>
<?=date("M d, Y - H:i", strtotime($post['date_time']))?>
</small>
</div>
</div>
</article>
<?php endwhile;?>
</div>
</section>
<?php else: ?>
<div class="alert_message_error_section_extra-margin">
<p>No post found</p>
</div>
<?php endif;?>
<!--End Posts-->
<section class="category_buttons">
<div class="container category_buttons-container">
<?php
$sql = "SELECT * FROM category";
$result = mysqli_query($conn, $sql);
while($category = mysqli_fetch_assoc($result)) :?>
<a href="category-post.php?id=<?= $category['id']?>" class="category_button"><?=$category['title']?></a>
<?php endwhile;?>
</div>
</section>
<?php
include "partial/footer.php";
?>