Can't create custom post type

Hi, I am trying to create custom post type (Projects), did by instruction, but I am getting this: ( Invalid section type (""))

Also create “Projects” page, but it’s showing this: (This page has no blueprint setup yet)

Seems did all like described, can’t understand what is wrong.

Please post your blueprint, probably some indentation error.

Thanks, which one: projects.yml? or project.yml?

Best both


I’m missing the site/sections/project.yml blueprint. And by the way the second line in your pages/projects.yml should be removed.

On a side note, please don’t post images of your code but rather post it here as code blocks.

headline: Projects
layout: cards
template: projects
  query: page.images.template("cover").first
  ratio: 3/2
  cover: true
info: "{{ page.year }}"

Ok, thanks. So, all is copied from instruction.

First part seems to work after some changes:

headline: Projects
type: pages
template: project
  query: page.images.template("cover").first
  ratio: 3/2
  cover: true
info: "{{ page.year }}"

Update: but it’s probably wrong, as subpages are acting like pages:
I am so frustrated, trying to find instructions, but they seem to lack details. For example in cookbook there is article about custom post types, but it shows output, and no step by step instruction how to create custom post type

You are showing us an image, but I don’t know where that page list is shown. Looks like that pops up in another part of site?

It was from panel, where all pages are listed. Seems very hard to understand for me, so I just copied all that I had for blog section, which works fine, and now projects seems to work :slight_smile:

But another question: which code would show the list of projects on Projects page? I mean what should be in /templates/projects.php?

Something like

<?php foreach($page->children()->listed() as $project): ?>
<h1><?= $project->title() ?></h1>
<?php endforeach ?>

And then depending what information you store in your pages.

Thank you, it’s working! Also can you please help to understand, how to change this: when I am ready to publish Project, its position by default is last. I can do it first manually, but if it’s 100 projects, that’s not convenient, also normally newest project should be displayed first. So how can I change this setting and show newest Project first by default?

And also is it compulsory for any page or subpage to have this Draft stage? Or it can be set to be published straight?

The draft state is compulsory, but you can use hooks to auto-publish pages directly after creation, in this case it would be the page.create:after hook.

If you use a date field in your projects, you could switch from (manual) sorting by number to sorting by date: Page blueprint | Kirby CMS

In the Panel or on frontend or both?

Thank you, tried this sorting by date and it’s working:
num: '{{ page.created.toDate("Ymd") }}'
Yes, same sort should be in panel and on frontpage.

Still, sometimes there will be need of additional manual sorting, so is it possible to have sorting by “date created” by default, plus this:

Or can be different: can be manual sorting, only that by default should be number 1.

Date based sorting doesn’t work with manual sorting, it just wouldn’t make sense. If you want manual sorting, you have to use standard numbered sorting. Theoretically, there is no need to set the default number for new pages to 1, because you can simply flip the order (using desc or asc or flip()) to get the desired result.

Please note that sorting the pages manually by dragging them with those handels actually changing the folder number.

Would you mind posting your images here?

I think clear with panel, but don’t understand, what code should I write in template? Tried different by these examples (, but not working.

I have:
<?php foreach($page->children()->listed() as $project): ?>
How should I change this to sort by date field desc?

Or would be best if they inherit the same sort from panel.

What do you mean about images? Which I should post?

<?php foreach($page->children()->listed()->sortBy('date', 'desc') as $project): ?>

Thank you! Working. First I confused with code for multiple fields. Also interesting, that it’s working with this code too:
$projects = page(‘projects’)->children()->listed()->sortBy(function ($page) {
return $page->date()->date();
}, ‘desc’);
foreach($projects as $project): ?>