joe_g Posted April 12, 2013 Share Posted April 12, 2013 Hi, is there a way to let a newly added page appear on top of the list in the backend instead on the bottom? (without loosing manual sorting) tried searching but couldn't find anything - hope I didn't miss some similar post thanks! J Link to comment Share on other sites More sharing options...
nik Posted April 12, 2013 Share Posted April 12, 2013 There's no way as far as I know, built-in one that is. I thought I'd seen a conversation on this subject but couldn't find one right away. This one may be helpful if you're creating pages programmatically though. 2 Link to comment Share on other sites More sharing options...
joe_g Posted April 12, 2013 Author Share Posted April 12, 2013 thanks! no direct solution but helpful Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 12, 2013 Share Posted April 12, 2013 The problem is scalability. Putting them on top wil give performance issues as it has to reassign the index for all siblings. 5 Link to comment Share on other sites More sharing options...
apeisa Posted April 13, 2013 Share Posted April 13, 2013 Could the new index be negative? 2 Link to comment Share on other sites More sharing options...
Wanze Posted April 13, 2013 Share Posted April 13, 2013 Could the new index be negative? the sort field in the pages table isn't "unsigned", so negative values should be possible. Link to comment Share on other sites More sharing options...
ryan Posted April 13, 2013 Share Posted April 13, 2013 The best way to have pages appear at the top of a list when they are created is to set their default sort field to be '-created' (or reverse created in the admin). But as for having a manual sorting, PW's admin will only add pages to the end of a manually sorted list. 1 Link to comment Share on other sites More sharing options...
thetuningspoon Posted April 17, 2013 Share Posted April 17, 2013 This is an issue I'm running into as well. How do I move an article from the bottom of the list to the top when the list gets to be really large? I'm working with a list of news articles, and by default my client wants to have the new articles show up at the top of the outputted list, but to be able to manually reorder if necessary. Is this possible? I'm concerned that they're not going to be too happy about having to do another step each time they create a new article. 1 Link to comment Share on other sites More sharing options...
ryan Posted April 20, 2013 Share Posted April 20, 2013 Manual sorting is intended for reasonably sized lists, like navigation. For large groups of pages that have a chronological basis, you should always use some kind of date sorting. If you need to go outside that in certain instances, then add a "sticky" or "featured" checkbox, so that the client can override what gets shown first on the front-end when they want to. For example, if we wanted to retrieve a list of all news articles by date, but with "featured" ones showing up first, we could do this: $articles = $pages->find("template=article, sort=-featured, sort=-date"); 3 Link to comment Share on other sites More sharing options...
thetuningspoon Posted April 25, 2013 Share Posted April 25, 2013 Thanks for the suggestion Ryan. For my purpose, manual sort with new pages added to the top would really be the first best solution. We can get around it for now, but it would definitely be a useful feature to have at some point 1 Link to comment Share on other sites More sharing options...
joe_g Posted May 1, 2013 Author Share Posted May 1, 2013 Here is my user scenario: I often run into the scenario where the frontpage shows perhaps the latest 10 posts, and the rest equals the archive. The editor usually would like to manually order the newest 10-20 posts, and forget about the rest – the rest is found other ways (filtering / tagging / archive). Currently the editors need to move things from the 'frontpage' into the 'archive', not a big problem, but they just need to be aware of the two different locations. Link to comment Share on other sites More sharing options...
Soma Posted May 1, 2013 Share Posted May 1, 2013 I would keep the structure flat and use date sorting. Moving posts from a "show on front" place to a "archive" place is most always not a good idea, in PW the structure is reflected in the URL and the URL of the post will change. So if someone linked to the post it will break (though there's a module that solves the issue with url redirects but it's questionable). To have an archive state for a post defined by a structure, where you have to move pages around, is something I would avoid generally. Having content live in a /archive/post1/ structure is always questionable, and if choosing to design such urls it would be done soft using urls segments. In your scenario I would keep the structure "flat" of the posts and if you want to define posts that show up on a up-front page, use a page field to select and sort them. Then render this page list out. 1 Link to comment Share on other sites More sharing options...
bfncs Posted May 12, 2013 Share Posted May 12, 2013 I second Soma's argument, it really is a problem if your URLs are dying fast, and already constructing it with a massive amount of URL direction is also not a really good idea. The approach with a page field should be working out nicely in your use case. You might write a smallish module that hooks into Pages::___save() and checks whether a saved page is newly created and a child of your archive page and if yes adds it to the pages field on your front page automatically to keep it comfortable for the editors. That being said, I also think, it would be great to have the possibility to add new pages with manual sorting on top in the backend. Can't imagine a simple and scalable way to do this without any slowish kind of indirection, though. 1 Link to comment Share on other sites More sharing options...
elabx Posted October 29, 2022 Share Posted October 29, 2022 On 4/25/2013 at 3:49 PM, thetuningspoon said: Thanks for the suggestion Ryan. For my purpose, manual sort with new pages added to the top would really be the first best solution. We can get around it for now, but it would definitely be a useful feature to have at some point Hi! @thetuningspoon this is a very old thread haha but wondering if you managed to figure this out? Maybe through a hook after page add? Link to comment Share on other sites More sharing options...
flydev Posted October 29, 2022 Share Posted October 29, 2022 4 minutes ago, elabx said: Maybe through a hook after page add? 1 Link to comment Share on other sites More sharing options...
adrian Posted October 30, 2022 Share Posted October 30, 2022 I think the easiest way is the AddNewChildFirst option in AdminOnSteroids. If you don't want to use that entire module, can you can grab the hook it uses: https://github.com/rolandtoth/AdminOnSteroids/blob/2e8f9c56dbc0d05edcb203d7dcf9af31eb862b02/AdminOnSteroids.module#L786-L795 Basically you're just setting the sort value of the new page to 0. 1 Link to comment Share on other sites More sharing options...
Gideon So Posted October 30, 2022 Share Posted October 30, 2022 Hi @joe_g $pages->addHookAfter('added', function(HookEvent $event) { $pages = $event->object; // The page that is being added $page = $event->arguments(0); // If the page passes some kind of test if($page->template == 'your-template-name') { // Set the sort value for the new page to zero (sibling sort will be automatically adjusted) $pages->sort($page, 0); } }); Put this piece of code into the ready.php. Hope this help. Gideon 1 Link to comment Share on other sites More sharing options...
bernhard Posted October 30, 2022 Share Posted October 30, 2022 If you are using custom page classes + RockMigrations MagicPages feature, then you can simply add this to your init() method: $this->createOnTop(); Here's the full code for a custom page class using that feature: <?php namespace ProcessWire; use RockMigrations\MagicPage; class BasicPagePage extends Page { use MagicPage; public function init() { // $this->setPageNameFromTitle(); // would also be possible :) $this->createOnTop(); } } 1 Link to comment Share on other sites More sharing options...
elabx Posted October 30, 2022 Share Posted October 30, 2022 14 hours ago, adrian said: I think the easiest way is the AddNewChildFirst option in AdminOnSteroids. If you don't want to use that entire module, can you can grab the hook it uses: https://github.com/rolandtoth/AdminOnSteroids/blob/2e8f9c56dbc0d05edcb203d7dcf9af31eb862b02/AdminOnSteroids.module#L786-L795 Basically you're just setting the sort value of the new page to 0. Exactly this! Solved! 8 hours ago, bernhard said: If you are using custom page classes + RockMigrations MagicPages feature, then you can simply add this to your init() method: Ohh!! This is neat ? Need to upgrade to latest RockMigrations, still on v1! 1 Link to comment Share on other sites More sharing options...
bernhard Posted October 30, 2022 Share Posted October 30, 2022 1 hour ago, elabx said: Ohh!! This is neat ? Need to upgrade to latest RockMigrations, still on v1! Magic Pages are great ? Note that it's not just a regular update as we are used to! So for existing projects it might be better to stay with RM1. But for new projects you should definitely have a look at RM2 - it's so much better in so many ways, but it will be a quick win if you are used to RM1 as the basic syntax/API did not change a lot ? Link to comment Share on other sites More sharing options...
joe_g Posted yesterday at 11:53 AM Author Share Posted yesterday at 11:53 AM On 10/30/2022 at 7:40 AM, Gideon So said: Hi @joe_g $pages->addHookAfter('added', function(HookEvent $event) { $pages = $event->object; // The page that is being added $page = $event->arguments(0); // If the page passes some kind of test if($page->template == 'your-template-name') { // Set the sort value for the new page to zero (sibling sort will be automatically adjusted) $pages->sort($page, 0); } }); Put this piece of code into the ready.php. Hope this help. Gideon this still works in 2024 :) (answering my own question from 2013 haha) 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now