Kategorieseitenpaginator #50
+47
-121
@@ -1,135 +1,61 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once "php/controller/showCategory-controller.php";
|
include_once "php/controller/showCategory-controller.php";
|
||||||
?>
|
?>
|
||||||
<?php
|
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
|
||||||
session_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($articles)){
|
<div class="category-results-container">
|
||||||
$totalResultsCount = count($articles);
|
<!-- Kategorie-Titel sicher ausgeben -->
|
||||||
|
<h1>Kategorie: <?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : 'Unbekannt'; ?></h1>
|
||||||
|
|
||||||
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 10;
|
<!-- 1. Die Artikel-Liste ausgeben -->
|
||||||
if (!in_array($limit, [10, 20, 50, 100])) {
|
<div class="articles-list">
|
||||||
$limit = 10;
|
<?php if (isset($articles) && !empty($articles)): ?>
|
||||||
}
|
<?php foreach ($articles as $article): ?>
|
||||||
|
<article class="article-item">
|
||||||
|
<!-- Sichere Objektausrufe über die Getter-Methoden -->
|
||||||
|
<h2><?php echo (isset($article) && !empty($article->getTitle())) ? htmlspecialchars($article->getTitle()) : 'Kein Titel'; ?></h2>
|
||||||
|
<p><?php echo (isset($article) && !empty($article->getContent())) ? htmlspecialchars($article->getContent()) : 'Kein Inhalt'; ?></p>
|
||||||
|
</article>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<p>Keine Artikel in dieser Kategorie gefunden.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
// Gesamtseitenzahl
|
<!-- 2. Der Paginator (Greift nur, wenn mehr als eine Seite existiert) -->
|
||||||
$totalPages = max(1, ceil($totalResultsCount / $limit));
|
<?php if (isset($totalPages) && $totalPages > 1): ?>
|
||||||
|
<form id="search-form-id" action="index.php" method="GET" style="display: inline;">
|
||||||
|
|
||||||
// Aktuelle Seite auslesen und validieren
|
<!-- Pfad und Kategorie als versteckte Felder mitsenden -->
|
||||||
$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
<input type="hidden" name="pfad" value="showCategory">
|
||||||
if ($currentPage < 1) {
|
<input type="hidden" name="category" value="<?php echo (isset($category) && !empty($category)) ? htmlspecialchars($category) : ''; ?>">
|
||||||
$currentPage = 1;
|
|
||||||
} elseif ($currentPage > $totalPages) {
|
|
||||||
$currentPage = $totalPages;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Startpunkt im Array berechnen (Offset)
|
<!-- Das Feld, das dein JS-Paginator befüllt (Nutzt Kurzform ?? für Fallback) -->
|
||||||
$offset = ($currentPage - 1) * $limit;
|
<input type="hidden" id="s-res-page-input" name="page" value="<?php echo (isset($page) && !empty($page)) ? $page : 1; ?>">
|
||||||
|
|
||||||
// Nur die Ergebnisse für die aktuelle Seite ausschneiden
|
|
||||||
//$results = array_slice($all_results, $offset, $limit);
|
|
||||||
$results = $articles;
|
|
||||||
$resultCount = count($results);
|
|
||||||
} else {
|
|
||||||
echo "fehler";
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<noscript>
|
|
||||||
Bitte JavaScript aktivieren!
|
|
||||||
</noscript>
|
|
||||||
<!--
|
|
||||||
Seite: Suchergebnisse
|
|
||||||
Inhalt: Zeigt die Ergebnisse einer Suche an
|
|
||||||
-->
|
|
||||||
<div class="s-res-layout-grid">
|
|
||||||
<?php include_once "includes/alertMessages.php"?>
|
|
||||||
|
|
||||||
<!-- Links: Seitenleiste für Filter und Suche -->
|
|
||||||
<aside class="s-res-sidebar">
|
|
||||||
|
|
||||||
<input type="hidden" id="s-res-page-input" name="page" value="<?php echo $_GET['page'] ?? 1; ?>">
|
|
||||||
|
|
||||||
<div class="s-res-sidebar-box">
|
|
||||||
<h3 class="s-res-sidebar-title">Sortierung</h3>
|
|
||||||
<?php $currentSort = $_SESSION['search_sort'] ?? 'alphabet'; ?>
|
|
||||||
<div class="s-res-filter-group">
|
|
||||||
<label class="s-res-filter-option">
|
|
||||||
<input type="radio" name="sort" value="alphabet" class="sort-radio" <?php echo $currentSort === 'alphabet' ? 'checked' : ''; ?>>
|
|
||||||
<span>Alphabetisch</span>
|
|
||||||
</label>
|
|
||||||
<label class="s-res-filter-option">
|
|
||||||
<input type="radio" name="sort" value="likes" class="sort-radio" <?php echo $currentSort === 'likes' ? 'checked' : ''; ?>>
|
|
||||||
<span>Beliebtheit (Likes)</span>
|
|
||||||
</label>
|
|
||||||
<label class="s-res-filter-option">
|
|
||||||
<input type="radio" name="sort" value="newest" class="sort-radio" <?php echo $currentSort === 'newest' ? 'checked' : ''; ?>>
|
|
||||||
<span>Neueste Beiträge</span>
|
|
||||||
</label>
|
|
||||||
<label class="s-res-filter-option">
|
|
||||||
<input type="radio" name="sort" value="oldest" class="sort-radio" <?php echo $currentSort === 'oldest' ? 'checked' : ''; ?>>
|
|
||||||
<span>Älteste Beiträge</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</aside>
|
|
||||||
|
|
||||||
<main class="s-res-main-content">
|
|
||||||
<!-- Ergebnisliste -->
|
|
||||||
<div class="s-res-list">
|
|
||||||
<?php
|
|
||||||
if (!empty($results)): ?>
|
|
||||||
|
|
||||||
<?php foreach ($results as $item):
|
|
||||||
// Anzahl der Likes ermitteln (falls es ein Array ist, zählen; falls Zahl, direkt nutzen)
|
|
||||||
$likesCount = isset($item['likes']) && is_array($item['likes']) ? count($item['likes']) : ($item['likes'] ?? 0);
|
|
||||||
?>
|
|
||||||
<div class="s-res-item" data-likes="<?php echo $likesCount; ?>" data-category="<?php echo strtolower($item['category'] ?? ''); ?>">
|
|
||||||
<div class="s-res-content">
|
|
||||||
<h2 class="s-res-item-title">
|
|
||||||
<a href="index.php?pfad=showArticle&id=<?php echo $item['id']; ?>" class="s-res-link">
|
|
||||||
<?php echo htmlspecialchars($item['title']); ?>
|
|
||||||
</a>
|
|
||||||
</h2>
|
|
||||||
<div class="s-res-meta-row">
|
|
||||||
<p class="s-res-author">Von: <span class="s-res-author-name"><?php echo htmlspecialchars($item['author']); ?></span></p>
|
|
||||||
|
|
||||||
<span class="s-res-likes">
|
|
||||||
❤️ <?php echo $likesCount; ?>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="s-res-arrow">→</div>
|
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="s-res-pagination-footer">
|
|
||||||
|
|
||||||
<!-- Auswahl der Ergebnisse pro Seite -->
|
|
||||||
<div class="s-res-limit-selector">
|
|
||||||
<label for="s-res-per-page" class="s-res-limit-label">Ergebnisse pro Seite:</label>
|
|
||||||
<select id="s-res-per-page" name="limit" class="s-res-limit-select">
|
|
||||||
<option value="10" <?php echo $limit === 10 ? 'selected' : ''; ?>>10</option>
|
|
||||||
<option value="20" <?php echo $limit === 20 ? 'selected' : ''; ?>>20</option>
|
|
||||||
<option value="50" <?php echo $limit === 50 ? 'selected' : ''; ?>>50</option>
|
|
||||||
<option value="100" <?php echo $limit === 100 ? 'selected' : ''; ?>>100</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<!-- Die Navigations-Buttons -->
|
||||||
<div class="s-res-page-navigation">
|
<div class="s-res-page-navigation">
|
||||||
<button type="button" class="s-res-page-btn" id="prev-page-btn" data-page="0">«</button>
|
|
||||||
|
|
||||||
<span id="dynamic-page-numbers"></span>
|
<!-- Zurück-Button -->
|
||||||
|
<?php $currentPage = $page ?? 1; ?>
|
||||||
|
<button type="button" class="s-res-page-btn" data-page="<?php echo $currentPage - 1; ?>" <?php echo ($currentPage <= 1) ? 'disabled' : ''; ?>>
|
||||||
|
« Zurück
|
||||||
|
</button>
|
||||||
|
|
||||||
<button type="button" class="s-res-page-btn" id="next-page-btn" data-page="2">»</button>
|
<!-- Seitenzahlen generieren -->
|
||||||
|
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
|
||||||
|
<button type="button"
|
||||||
|
class="s-res-page-btn <?php echo ($i === $currentPage) ? 'active' : ''; ?>"
|
||||||
|
data-page="<?php echo $i; ?>"
|
||||||
|
<?php echo ($i === $currentPage) ? 'disabled' : ''; ?>>
|
||||||
|
<?php echo $i; ?>
|
||||||
|
</button>
|
||||||
|
<?php endfor; ?>
|
||||||
|
|
||||||
|
<!-- Vor-Button -->
|
||||||
|
<button type="button" class="s-res-page-btn" data-page="<?php echo $currentPage + 1; ?>" <?php echo ($currentPage >= $totalPages) ? 'disabled' : ''; ?>>
|
||||||
|
Weiter »
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
<?php endif; ?>
|
||||||
</main>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user