简体   繁体   中英

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

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

@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. Every time a content item is tagged with the term the TermsPartHandler refresh the count.

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

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

And then for each terms from a taxonomy just count the ContentItems

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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