Umbraco统计活动内容页
我想获得Umbraco站点中节点的页面数,输出如下:Umbraco统计活动内容页,umbraco,umbraco6,Umbraco,Umbraco6,我想获得Umbraco站点中节点的页面数,输出如下: 根(9个子节点) 第一个文件夹(4个子节点) 文件1 文件2 文件3 文件4 第二个文件夹(3个子节点) 文件1 文件2 文件3 基本上,我是想看看在一个给定的网站上有多少活跃的内容,并想出一种划分工作的方法。有没有合理的方法获取这些信息?这对我来说很有效: App_代码文件夹中的subjections.cs using System; using System.Collections.Generic; using Syst
- 根(9个子节点)
- 第一个文件夹(4个子节点)
- 文件1
- 文件2
- 文件3
- 文件4
- 第二个文件夹(3个子节点)
- 文件1
- 文件2
- 文件3
- 第一个文件夹(4个子节点)
- App_代码文件夹中的subjections.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using umbraco.presentation; using umbraco.presentation.nodeFactory; public static class ExtensionMethods { public static IEnumerable<Node> AllDescendants(this Node node) { foreach (Node child in node.Children) { yield return child; foreach (Node grandChild in child.AllDescendants()) yield return grandChild; } } }
使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用umbraco.presentation; 使用umbraco.presentation.nodeFactory; 公共静态类扩展方法 { 公共静态IEnumerable所有子体(此节点) { foreach(Node.Children中的节点子节点) { 退换子女; foreach(child.allsubstands()中的节点孙子节点) 收益回报孙子; } } }
- 剃刀视图
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using umbraco.presentation.nodeFactory; @{ Layout = ""; } @functions{ public string CreateSitemap() { var temp = "<ul class='collapsibleList'>" + sitemap(-1) + "</ul>" + Environment.NewLine; return temp; } public string sitemap(int nodeID) { var rootNode = new umbraco.presentation.nodeFactory.Node(nodeID); var sitemapstring = "<li>" + rootNode.Name + " (" + rootNode.AllDescendants().Count() + ") <span style='font-size:9px'>" + rootNode.NodeTypeAlias + "</span></li>" + Environment.NewLine; if (rootNode.Children.Count > 0) { sitemapstring += "<ul>" + Environment.NewLine; sitemapstring = rootNode.Children.Cast<Node>().Aggregate(sitemapstring, (current, node) => current + sitemap(node.Id)); sitemapstring += "</ul>" + Environment.NewLine; } return sitemapstring; } } <body> @Html.Raw(CreateSitemap()) </body>
@继承Umbraco.Web.Mvc.UmbracoTemplatePage @使用umbraco.presentation.nodeFactory; @{ 布局=”; } @功能{ 公共字符串CreateSitemap() { var temp=“
- ”+站点地图(-1)+“
- ”+rootNode.Name+”(“+rootNode.allsubstands().Count()+”)“+rootNode.NodeTypeAlias+”
“+Environment.NewLine; 如果(rootNode.Children.Count>0) { sitemapstring+=“- ”+Environment.NewLine;
sitemapstring=rootNode.Children.Cast().Aggregate(sitemapstring,(current,node)=>current+sitemap(node.Id));
sitemapstring+=“