简体   繁体   English

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

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

I'm trying to display a List of my taxonomies with a count of content items in it. 我正在尝试显示我的分类法列表,其中包含一些内容项。

But i can't find out how to do it. 但我无法找到如何做到这一点。 i tried to modify TaxonomyItem.cshtml 我试图修改TaxonomyItem.cshtml

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

@terms.Count() @ terms.Count()

but this gives my only the count of taxonomy items, not the count of content items inside each taxonomy. 但这只给出了我的分类项目,而不是每个分类中的内容项目数。

how can i display this? 我怎么能显示这个?

EDIT 编辑

Each term has the Count of ContentItems, is the Count value of TermPart.Count. 每个术语都有Count of ContentItems,是TermPart.Count的Count值。 Every time a content item is tagged with the term the TermsPartHandler refresh the count. 每次使用术语标记内容项时,TermsPartHandler都会刷新计数。

The TaxonomyItem template uses DisplayChildren, and for each Term it will render the template TaxonomyItemLink. 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)

That is the count of items for that Term, not the Taxonomy. 这是该术语的项目数,而不是分类。

Simply resolve taxonomy service from TaxonomyItemLink.cshtml 只需从TaxonomyItemLink.cshtml解析分类法服务

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

And then for each terms from a taxonomy just count the ContentItems 然后,对于分类中的每个术语,只需计算ContentItems

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

}

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

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