Projects in Showcase not sorting

Hi there
I’m having an issue with the showcase section of the projects page. No matter what i try it keeps re-arranging itself on each refresh. I have tried to change the sortby settings to date but nothing happens.

If i set the numbers of the folders in the /projects section it stays the same until i refresh and then all the projects are ordered differently.

Am i missing something here?
Any help is appreciated.

Can you post a short example of your code? This would help to figure it out :slight_smile:

I assume we are talking about the order in the Panel. Could you post your blueprint, please?

If frontend, then your template/showcase snippet.

Hi, thanks. Sorry, yes in the panel if i edit the projects section to re-order the project pages when i drag one the other pages move too, nothing stays put! The showcase code is below and the blueprint underneath that.

    <ul class="showcase grid gutter-1">

  <?php foreach($projects as $project): ?>

    <li class="showcase-item column">
        <a href="<?= $project->url() ?>" class="showcase-link">
          <?php if($image = $project->images()->sortBy('sort', 'date')->first()): $thumb = $image->crop(600, 300); ?>
            <img src="<?= $thumb->url() ?>" alt="Thumbnail for <?= $project->title()->html() ?>" class="showcase-image" />
          <?php endif ?>
          <div class="showcase-caption">
            <h3 class="showcase-title"><?= $project->title()->html() ?></h3>
          </div>
        </a>
    </li>

  <?php endforeach ?>

Blueprint:

    title: Projects

    files: false

    pages:
      template: project

    options: 
      template: false  
      status: false  
      url: false  

    fields:
      title:
        label: Title
        type:  text

      text:
        label: Text
        type:  textarea

Thanks!

To determine the sort order of the subpages in the Panel, you have to set the sort option: https://k2.getkirby.com/docs/panel/blueprints/subpages-settings#sorting-of-subpages

For example:

pages:
  template: project
  sort: year desc

That just applies to the order in which the subpages are displayed in the sidebar of the Panel. It does not affect the sort order of the folders themselves.

By default, subpages are sorted by a prepended number (1_, 2_ etc, visible pages). If you drag and drop the subpages, you change their folder numbers in the filesystem. That will affect the order in the frontend, depending what you sort by in your template.

Folder numbering is controlled via the num option in your blueprint. Instead of the default numbering, you can also sort by date or alphabetically.

Hi ok, so adding sort to the blueprint will keep the panel order in place, thank you. But how do I keep the frontend order fixed on the actual webpage?

I’ve names the folders with the prepended number but they still don’t stay in that order for some reason. Sorry to be a pain. Thank you

Unfortunately, I don’t see how you have defined $projects. Is that still in its original state or have you changed anything?

The showcase snippet defines $projects like this:

$projects = page('projects')->children()->visible();

So that is according to the order in the file system (1_ to x_). If you change that order by dragging and dropping the projects around in the Panel, the prepended numbers will change and so will the order of your projects in the frontend.

that is the same code as my snippet. What happens is if i edit a project, in any way, simply going into a project in the panel and saving the page, when i go back to the showcase (projects) page the order of the showcase has altered. It is becoming completely frustrating but i’m meditating!

I just don’t know why the order won’t stay put. I’ve used Kirby for other sites and this has never happened.

But in the filesystem the order numbers remain the same, only the sort order in the frontend changes? That sounds weird.

no the order numbers change too, ghost in the machine!

I guess what i’m saying is i want manual control of all my subpages

Is there a hook somewhere that shuffles the pages when updating?

I don’t think so, where would i find that (I haven’t added one)

So you are using an unaltered Starterkit?

Hooks can live in the config or in a plugin.

i’m using a starterkit, i have no plugins. The config puts the homepage as the projects page but thats it

Must be a ghost fooling you, then.

Could you send me a zip of that ghost project?

1 Like

Problem was old Kirby version