-
Notifications
You must be signed in to change notification settings - Fork 0
/
category_details.php
70 lines (63 loc) · 2.41 KB
/
category_details.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
<?php
require_once 'services/db.php';
require_once 'services/users.php';
$db = OpenCon();
$category_id = $_GET['category_id'];
if (is_numeric($category_id)) {
$raw_query = "SELECT
posts.id as id,
categories.id as category_id,
categories.title as category_title,
categories.description as category_description,
categories.tag as category_tag,
posts.title as title,
posts.text as `text`,
posts.pubdate as pubdate,
posts.author_id as author_id
FROM categories JOIN posts ON categories.id = posts.category_id
WHERE categories.id = " . (int) $category_id . ';';
$category_posts = $db->query($raw_query)->fetchAll();
$sample_post = $category_posts[0];
$category = array(
'id' => $sample_post['category_id'],
'description' => $sample_post['category_id'],
'title' => $sample_post['category_title'],
'tag' => $sample_post['category_tag']
);
} else {
$category_posts = [];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php require 'components/base_head.php' ?>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<?php require 'components/navbar.php' ?>
<script src='js/navbar.js'></script>
<script>
navbarSetActiveButton('categories_link')
</script>
<div class="container">
<?php if($category_posts): ?>
<nav class='mt-4' aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/categories.php">Categories</a></li>
<li class="breadcrumb-item active" aria-current="page"><?=$category['title'] ?></li>
</ol>
</nav>
<h1 class="mt-2"><?=$category['title'] ?></h1>
<p class="text-muted text-uppercase fw-light">Все посты</p>
<?php foreach($category_posts as $post): ?>
<?php require 'components/post_card.php' ?>
<?php endforeach; ?>
<?php else: ?>
<h1 class="mt-5">404 :(</h1>
<p>Категория не найдена. <a href="/" class="text-reset">Перейти на главную.</a></p>
<?php endif; ?>
</div>
<?php require 'components/footer.php' ?>
<?php require 'components/base_scripts.php' ?>
</body>