简体   繁体   中英

Umbraco: Set page order always last in content tree

Eg. content structure

-Home
  -Page1
  -Page2
  -Page3

Q: How can I set the default order of Page3 to be always last? if other pages are created at this level?

Like this:

 -Home
  -Page1
  -Page2
  -Page4
  -Page3

If you are looking to manage this with Umbraco admin, according to my experience it is not possible with the Umbraco Admin UI to set some property to manage it. Umbraco table umbracoNode contains the sortOrder of the pages and it will automatically created when you creates a page and it will be last page.

You have to write some custom code for page creation events in umbraco backoffice. This can be done, what is the Umbraco version are you using?

You could do it in the code when a new content node is saved. So when you save a node, first check for the right alias type, and then do your sorting thing..

Create a new class which inherit from Umbraco.Core.ApplicationEventHandler

Overwrite ApplicationStarted:

protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        ContentService.Published += ContentService_Published;
        base.ApplicationStarted(umbracoApplication, applicationContext);
    }

Create a new method

private void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
    {
        foreach (var content in e.PublishedEntities)
        {
            if (content.ContentType.Alias != "YOUR CONTENT ALIAS")
                continue;
            //Do your sorting here

        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM