2022-12-30 03:25:40 +00:00
|
|
|
<?php
|
2023-03-07 01:23:47 +00:00
|
|
|
include 'partials/header.php';
|
2022-12-30 03:25:40 +00:00
|
|
|
|
2023-03-07 01:23:47 +00:00
|
|
|
//fetch posts if id is set
|
|
|
|
if(isset($_GET['id'])){
|
|
|
|
$id=filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
|
|
|
|
$query= "SELECT * FROM posts WHERE category_id=$id ORDER BY date_time DESC";
|
|
|
|
$posts=mysqli_query($connection,$query);
|
|
|
|
}else{
|
|
|
|
header('location: ' . ROOT_URL . 'blog.php');
|
|
|
|
}
|
2022-12-30 03:25:40 +00:00
|
|
|
|
|
|
|
|
2023-03-07 01:23:47 +00:00
|
|
|
?>
|
2022-12-30 03:25:40 +00:00
|
|
|
|
|
|
|
|
2023-03-07 01:23:47 +00:00
|
|
|
<header class="category__title">
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$category_query="SELECT * FROM categories WHERE id=$id";
|
|
|
|
$category_result=mysqli_query($connection,$category_query);
|
|
|
|
$category=mysqli_fetch_assoc($category_result);
|
|
|
|
?>
|
|
|
|
<h2><?= $category['title'] ?></h2>
|
|
|
|
</header>
|
2022-12-30 03:25:40 +00:00
|
|
|
|
|
|
|
|
2023-03-07 01:23:47 +00:00
|
|
|
<?php if ((mysqli_num_rows($posts)) > 0) : ?>
|
|
|
|
<section class="posts">
|
2022-12-30 03:25:40 +00:00
|
|
|
|
2023-03-07 01:23:47 +00:00
|
|
|
<div class="container posts__container">
|
|
|
|
<?php while ($post=mysqli_fetch_assoc($posts)) :?>
|
|
|
|
<article class="post">
|
|
|
|
<div class="post__thumbnail">
|
|
|
|
<img src="./images/<?=$post['thumbnail']?>" >
|
2022-12-30 03:25:40 +00:00
|
|
|
</div>
|
2023-03-07 01:23:47 +00:00
|
|
|
<div class="post__info">
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
$author_id=$post['author_id'];
|
|
|
|
$author_query="SELECT * FROM users WHERE id=$author_id";
|
|
|
|
$author_result=mysqli_query($connection,$author_query);
|
|
|
|
$author=mysqli_fetch_assoc($author_result);
|
|
|
|
|
|
|
|
?>
|
|
|
|
<h3 class="post__title"><a href="post.php?id=<?=$post["id"]?>" >
|
|
|
|
<?=$post['title']?>
|
|
|
|
</a></h3>
|
|
|
|
<p class="post__body">
|
|
|
|
<?= substr($post['body'],0,150) ?>...
|
|
|
|
</p>
|
|
|
|
<div class="post__author">
|
|
|
|
<div class="post__author-avatar">
|
|
|
|
<img src="./images/<?= $author['avatar'] ?>">
|
|
|
|
</div>
|
|
|
|
<div class="post__author-info">
|
|
|
|
<h5>By: <?= "{$author['firstname']} {$author['lastname']}" ?></h5>
|
|
|
|
<small>
|
|
|
|
<?=date("M d, Y -H:i" , strtotime($post['date_time']))?>
|
|
|
|
</small>
|
|
|
|
</div>
|
2022-12-30 03:25:40 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-03-07 01:23:47 +00:00
|
|
|
</article>
|
|
|
|
<?php endwhile ?>
|
2022-12-30 03:25:40 +00:00
|
|
|
|
2023-03-07 01:23:47 +00:00
|
|
|
|
2022-12-30 03:25:40 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</section>
|
2023-03-07 01:23:47 +00:00
|
|
|
<?php else : ?>
|
|
|
|
<div class="alert__message error lg">
|
|
|
|
<p>
|
|
|
|
No posts found for this category
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<?php endif ?>
|
2022-12-30 03:25:40 +00:00
|
|
|
<!--=====================================================================
|
|
|
|
==========================END OF THE POSTS===============================
|
|
|
|
=================================================================== -->
|
|
|
|
<section class="category__buttons">
|
2023-03-07 01:23:47 +00:00
|
|
|
<div class="container category__buttons-container">
|
|
|
|
<?php
|
|
|
|
$all_categories_query="SELECT * FROM categories ";
|
|
|
|
$all_categories_result=mysqli_query($connection,$all_categories_query);
|
|
|
|
|
|
|
|
?>
|
|
|
|
<?php while ( $category=mysqli_fetch_assoc($all_categories_result) ) : ?>
|
|
|
|
<a href="<?=ROOT_URL?>category-posts.php?id=<?=$category['id']?>" class="category__button"><?=$category['title']?></a>
|
|
|
|
<?php endwhile?>
|
|
|
|
</div>
|
|
|
|
</section>
|
2022-12-30 03:25:40 +00:00
|
|
|
<!--=======================END OF CATEGORY ===================================-->
|
|
|
|
|
|
|
|
|
|
|
|
<?php
|
|
|
|
include './partials/footer.php';
|
|
|
|
?>
|