-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
45 lines (33 loc) · 1.19 KB
/
index.php
File metadata and controls
45 lines (33 loc) · 1.19 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
<?php
require 'includes/init.php';
$conn = require 'includes/db.php';
// if no query string, page number is 1. Check 'Null coalescing operator'
//$paginator = new Paginator(isset($_GET['page']) ? $_GET['page'] : 1, 4);
$paginator = new Paginator($_GET['page'] ?? 1, 4, Article::getTotal($conn));
$articles = Article::getPage($conn, $paginator->limit, $paginator->offset);
?>
<?php require 'includes/header.php'; ?>
<?php if (empty($articles)): ?>
<p>No articles found.</p>
<?php else: ?>
<ul>
<?php foreach ($articles as $article): ?>
<li>
<article>
<h2><a href="article.php?id=<?= $article['id']; ?>"><?= htmlspecialchars($article['title']); ?></a></h2>
<?php if ($article['category_names']) : ?>
<p>Categories:
<?php foreach ($article['category_names'] as $name) : ?>
<?php var_dump($name); ?>
<?= htmlspecialchars($name); ?>
<?php endforeach; ?>
</p>
<?php endif; ?>
<p><?= htmlspecialchars($article['content']); ?></p>
</article>
</li>
<?php endforeach; ?>
</ul>
<?php require 'includes/pagination.php'; ?>
<?php endif; ?>
<?php require 'includes/footer.php'; ?>