sortieren nach likes nun moeglich
This commit is contained in:
@@ -62,6 +62,10 @@ $resultCount = count($results);
|
|||||||
<input type="radio" name="sort" value="alphabet" class="sort-radio" <?php echo $currentSort === 'alphabet' ? 'checked' : ''; ?>>
|
<input type="radio" name="sort" value="alphabet" class="sort-radio" <?php echo $currentSort === 'alphabet' ? 'checked' : ''; ?>>
|
||||||
<span>Alphabetisch</span>
|
<span>Alphabetisch</span>
|
||||||
</label>
|
</label>
|
||||||
|
<label class="s-res-filter-option">
|
||||||
|
<input type="radio" name="sort" value="likes" class="sort-radio" <?php echo $currentSort === 'likes' ? 'checked' : ''; ?>>
|
||||||
|
<span>Beliebtheit</span>
|
||||||
|
</label>
|
||||||
<label class="s-res-filter-option">
|
<label class="s-res-filter-option">
|
||||||
<input type="radio" name="sort" value="newest" class="sort-radio" <?php echo $currentSort === 'newest' ? 'checked' : ''; ?>>
|
<input type="radio" name="sort" value="newest" class="sort-radio" <?php echo $currentSort === 'newest' ? 'checked' : ''; ?>>
|
||||||
<span>Neueste Beiträge</span>
|
<span>Neueste Beiträge</span>
|
||||||
@@ -90,7 +94,7 @@ $resultCount = count($results);
|
|||||||
if (!empty($results)): ?>
|
if (!empty($results)): ?>
|
||||||
|
|
||||||
<?php foreach ($results as $item): ?>
|
<?php foreach ($results as $item): ?>
|
||||||
<div class="s-res-item">
|
<div class="s-res-item" data-likes="<?php echo $item['likes'] ?? 0; ?>">
|
||||||
<div class="s-res-content">
|
<div class="s-res-content">
|
||||||
<h2 class="s-res-item-title">
|
<h2 class="s-res-item-title">
|
||||||
<a href="index.php?pfad=showArticle&id=<?php echo $item['id']; ?>" class="s-res-link">
|
<a href="index.php?pfad=showArticle&id=<?php echo $item['id']; ?>" class="s-res-link">
|
||||||
@@ -98,6 +102,10 @@ $resultCount = count($results);
|
|||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
<p class="s-res-author">Von: <span class="s-res-author-name"><?php echo htmlspecialchars($item['author']); ?></span></p>
|
<p class="s-res-author">Von: <span class="s-res-author-name"><?php echo htmlspecialchars($item['author']); ?></span></p>
|
||||||
|
|
||||||
|
<p class="s-res-likes-display" style="font-size: 0.85rem; color: #64748b; margin-top: 4px;">
|
||||||
|
👍 <?php echo $item['likes'] ?? 0; ?> Likes
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="s-res-arrow">→</div>
|
<div class="s-res-arrow">→</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+9
-4
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
function initClientSorter() {
|
function initSorter() {
|
||||||
const listContainer = document.querySelector('.s-res-list');
|
const listContainer = document.querySelector('.s-res-list');
|
||||||
const sortRadios = document.querySelectorAll('.sort-radio');
|
const sortRadios = document.querySelectorAll('.sort-radio');
|
||||||
|
|
||||||
@@ -12,7 +12,12 @@ function initClientSorter() {
|
|||||||
const sortValue = this.value;
|
const sortValue = this.value;
|
||||||
|
|
||||||
cards.sort((a, b) => {
|
cards.sort((a, b) => {
|
||||||
if (sortValue === 'alphabet') {
|
if (sortValue === 'likes') {
|
||||||
|
const likesA = parseInt(a.getAttribute('data-likes') || '0', 10);
|
||||||
|
const likesB = parseInt(b.getAttribute('data-likes') || '0', 10);
|
||||||
|
return likesB - likesA;
|
||||||
|
}
|
||||||
|
else if (sortValue === 'alphabet') {
|
||||||
// alphabetische sortierung
|
// alphabetische sortierung
|
||||||
const titleA = a.querySelector('.s-res-link').textContent.trim().toLowerCase();
|
const titleA = a.querySelector('.s-res-link').textContent.trim().toLowerCase();
|
||||||
const titleB = b.querySelector('.s-res-link').textContent.trim().toLowerCase();
|
const titleB = b.querySelector('.s-res-link').textContent.trim().toLowerCase();
|
||||||
@@ -39,7 +44,7 @@ function initClientSorter() {
|
|||||||
|
|
||||||
// ist das DOM bereits vollständig aufgebaut?
|
// ist das DOM bereits vollständig aufgebaut?
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', initClientSorter);
|
document.addEventListener('DOMContentLoaded', initSorter);
|
||||||
} else {
|
} else {
|
||||||
initClientSorter();
|
initSorter();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user