In a blog page I created, the user can create posts labeled either as “news” or “event”. The “event”-posts have an additional field for an event date.
post.yml
fields:
category:
type: select
required: true
default: news
options:
news: News
event: Event
eventdate:
label: Event date
type: date
display: DD-MM-YYYY
when:
category: event
required: true
text:
type: textarea
In the template, the posts are sorted by publication date:
blog.php
<ul>
<?php foreach ($page->children()->listed()->sortBy('date', 'desc') as $post) : ?>
...
<?php endforeach ?>
</ul>
Now here comes my problem: If a new event gets added spontaneously, it always appears at the top of the sorting, even if the event date is earlier than that of a previously created event (because the sorting is done by publication date).
If I set the sorting to
<ul>
<?php foreach ($page->children()->listed()->sortBy('eventdate', 'desc', 'date', 'desc') as $post) : ?>
...
<?php endforeach ?>
</ul>
all the events are rendered first (because there is no event date on the “news” categorized posts).
So how can I fix that?
I would like to use the event date for the event posts and the publication date for the news posts and then sort all posts by their date.
Any help?