繁体   English   中英

在TaxonomyItem Shape中显示分类项中的内容项数

[英]Display Number of Content Items in Taxonomy Item in TaxonomyItem Shape

我正在尝试显示我的分类法列表,其中包含一些内容项。

但我无法找到如何做到这一点。 我试图修改TaxonomyItem.cshtml

var terms = (IEnumerable<Orchard.Taxonomies.Models.TermPart>)Model.Taxonomy.TaxonomyPart.Terms;

@ terms.Count()

但这只给出了我的分类项目,而不是每个分类中的内容项目数。

我怎么能显示这个?

编辑

每个术语都有Count of ContentItems,是TermPart.Count的Count值。 每次使用术语标记内容项时,TermsPartHandler都会刷新计数。

TaxonomyItem模板使用DisplayChildren,对于每个Term,它将呈现模板TaxonomyItemLink。

@*
   This shape is displayed for a TermPart when in a Taxonomy details page.

   Alternates:
   - TaxonomyItemLink__[HtmlClassifiedTaxonomyName]
   - TaxonomyItemLink__[HtmlClassifiedTaxonomyName]__[HtmlClassifiedTermName]
*@
@using Orchard.Taxonomies.Models
@{
   TermPart part = Model.ContentPart;
}

<span> This is the number of content items with this Term @part.Count </span>   

@Html.ItemDisplayLink(part)

这是该术语的项目数,而不是分类。

只需从TaxonomyItemLink.cshtml解析分类法服务

var _taxonomyService = WorkContext.Resolve<Orchard.Taxonomies.Services.ITaxonomyService>();

然后,对于分类中的每个术语,只需计算ContentItems

@{
  var NumberOfContentItems = _taxonomyService.GetContentItems(part).Count(); 

}

暂无
暂无

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

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