Hello! I would greatly appreciate any help with this problem I’m currently facing: I have a “news index” page, which displays children “news” pages inside of it. I’ve sorted the news pages by num:published, and this works for when I call for them in my newsindex.php. However, in the panel itself, the news pages are still appearing in what seems to be alphabetical order, rather than in order of publication date.
My newsindex.yml looks like this:
title: News Index
num: published
options:
title: false
status: false
move: false
duplicate: false
delete: false
changeSlug: false
sections:
drafts:
headline: Drafts
type: pages
status: draft
image:
ratio: 5/4
cover: true
template: news
info: "{{page.published}}, {{page.type}}"
published:
headline: Published
type: pages
layout: cards
status: published
image:
ratio: 5/4
cover: true
template: news
info: "{{page.published}}, {{page.type}}"
min: 1
search: true
And my news.yml looks like this:
title: News
num: published
columns:
- width: 1/2
sections:
info:
type: fields
fields:
Title:
type: text
required: true
published:
label: Published on
type: date
default: now
So, in my newsindex.php, when I try to display all the news pages in reverse chronological order of their “published on” dates via $news = $page->children()->listed()->sortBy('published', 'desc');
, they sequence correctly.
However, in the panel itself, they appear in alphabetical order, despite the num: published
stipulation. I also noticed that in the actual content folder itself, the news folders are being prepended with (1_, 2_, 3_) instead of the 0_ that they originally generated with (I’m not sure what caused this; I’ve tried manually renaming the folder back to all starting with 0_, but they’ve reverted to numerical sequencing again).
On a related note, is there a way to append the date set by “published on” to the url/folder name of a page? I’ve tried to do so through models/news.php, but what I have so far only prepends the date of when I set the page status from draft to published (so, in other words, “today”), rather than the “published on” date that I manually set, which could be years in the past:
<?php
use Kirby\Cms\Page;
use Kirby\Toolkit\Str;
class NewsPage extends Page
{
public static function create(array $props): Page
{
// Get the 'published' field from content props
$published = $props['content']['published'] ?? null;
// Format the published date (make sure it's valid)
if ($published) {
$date = date('Y-m-d', strtotime($published));
} else {
// $date = date('Y-m-d'); // fallback to now if field is missing
}
// Append the date to the slug
if (!empty($props['slug'])) {
$props['slug'] = $props['slug'] . '-' . $date;
}
return parent::create($props);
}
}