Jump to content

New page on top?


joe_g
 Share

Recommended Posts

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

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.

  • Like 2
Link to comment
Share on other sites

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. 

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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"); 
  • Like 3
Link to comment
Share on other sites

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

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.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

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.

  • Like 1
Link to comment
Share on other sites

  • 9 years later...
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

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.

 

  • Like 1
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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();
  }
}

 

  • Like 1
Link to comment
Share on other sites

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!

  • Like 1
Link to comment
Share on other sites

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

  • 1 year later...
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)

  • Like 1
  • Haha 1
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...