Jump to content

Pin page to top of page tree


Nico Knoll
 Share

Recommended Posts

You can do it on the template with $array->shift()

echo $array->shift()->title;
foreach($array->find("sort=date") as $item) echo $item->title;

edit: Or, if you want the complete array:

$first = $array->shift();
$final = $array->find("sort=date")->prepend($first);
  • Like 1
Link to comment
Share on other sites

You could also create and add a checkbox field to your template(s) and call it something like "sticky". When a page has the box checked, it will stick to the top of the list. Then when you perform the call to load your pages, sort by -sticky first, then by -date, i.e.

$pages->find("parent=/news/, sort=-sticky, sort=-date");
Link to comment
Share on other sites

I think so. Parent pages don't currently support multiple built-in sort fields for children (like in the API), so it would have to be one sort field or the other. That makes it difficult to pin a page in the admin, even if you can do it easily in your own site. Down the road a bit I think we'll have to add multiple sort fields, which would solve this pretty easily.

Link to comment
Share on other sites

  • 1 year later...

I think so. Parent pages don't currently support multiple built-in sort fields for children (like in the API), so it would have to be one sort field or the other. That makes it difficult to pin a page in the admin, even if you can do it easily in your own site. Down the road a bit I think we'll have to add multiple sort fields, which would solve this pretty easily.

Is there something new to this, since this thread is over a year old?

Well, thank you for the code but I meant in the backend page tree. (I would need a module I guess)

@Nico: if you have done it, - how have you done it?

In the backend I want to have pagetree children sorted by a archive number descending, but also want to be able to manually drag some pages to the top of the tree.

All new childpages will be created via API bootsstrapped script. If it is possible with API to add each of them to the top of the page tree, this would allready solve my needs.

Any pointers for that?

Link to comment
Share on other sites

  • 6 years later...
On 5/4/2012 at 8:56 PM, ryan said:

You could also create and add a checkbox field to your template(s) and call it something like "sticky". When a page has the box checked, it will stick to the top of the list. Then when you perform the call to load your pages, sort by -sticky first, then by -date, i.e.


$pages->find("parent=/news/, sort=-sticky, sort=-date");
 

@ryan, I know it's an ancient thread, but I'm slowly finishing my first public/client site with PW and this "sort=-sticky" trick has just blown my mind... ? I've got few crossing loops with different layouts and was trying to implement some kind of clever sticky mechanism onto all my find/sort structures. I was almost there with checkbox conditions but decided to look around here for a little help. Found this thread, adjusted and put your suggestion into my project and... started to dance and scream. ? PW is PHENOMENAL!

I'm learning PW API for few weeks intensively and I'm more and more thrilled. Thank You and all Devs so much for this wonderful CMF/CME!

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...