繁体   English   中英

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

[英]Umbraco: Set page order always last in content tree

例如。 内容结构

-Home
  -Page1
  -Page2
  -Page3

问:如何将Page3的默认顺序设置为始终为最后? 是否在此级别创建其他页面?

像这样:

 -Home
  -Page1
  -Page2
  -Page4
  -Page3

如果您希望使用Umbraco管理员进行管理,那么根据我的经验,无法使用Umbraco Admin UI设置一些属性来对其进行管理。 Umbraco表umbracoNode包含页面的sortOrder,当您创建页面时将自动创建该表,该表将是最后一页。

您必须为umbraco backoffice中的页面创建事件编写一些自定义代码。 可以做到,您使用的是Umbraco版本是什么?

保存新的内容节点时,可以在代码中完成此操作。 因此,当您保存节点时,请首先检查正确的别名类型,然后再进行排序。

创建一个继承自Umbraco.Core.ApplicationEventHandler的新类

覆盖ApplicationStarted:

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

创建一个新方法

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