简体   繁体   English

Umbraco:设置页面顺序始终在内容树中排在最后

[英]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? 问:如何将Page3的默认顺序设置为始终为最后? 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管理员进行管理,那么根据我的经验,无法使用Umbraco Admin UI设置一些属性来对其进行管理。 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. Umbraco表umbracoNode包含页面的sortOrder,当您创建页面时将自动创建该表,该表将是最后一页。

You have to write some custom code for page creation events in umbraco backoffice. 您必须为umbraco backoffice中的页面创建事件编写一些自定义代码。 This can be done, what is the Umbraco version are you using? 可以做到,您使用的是Umbraco版本是什么?

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 创建一个继承自Umbraco.Core.ApplicationEventHandler的新类

Overwrite ApplicationStarted: 覆盖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

        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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