Umbraco - Get all tags used in node / group

I used the GetTags() method under umbraco.cms.businesslogic.Tags.Tag to get all the tags under a group or node.

 var tags = umbraco.cms.businesslogic.Tags.Tag.GetTags("default"); 

But if umbraco.cms.businesslogic.Tags.Tag out of date, is there any other better alternative?

Also, does the new library offer tag-based node query?

+6
source share
3 answers

Ok, so Umbraco 7 has a new TagService library for handling tags.

To use all tags used,

 var service = UmbracoContext.Application.Services.TagService; var blogTags = service.GetAllTags("default"); 

To get the specific contents of the GetTaggedContentByTag() tag is a public method,

 var sports = service.TagService.GetTaggedContentByTag("Gaming"); 

It returns a TaggedEntity list and a TaggedEntity object with the EntityId property.

Source Courtesy: Jimbo Jones

+9
source

There is no need to call a tag service.

In umbraco 7 you can use this:

 var tags = Umbraco.TagQuery.GetAllTags(); 

or

 var tags = Umbraco.TagQuery.GetAllTags(group); 

And you can use

 var mycontents = Umbraco.TagQuery.GetContentByTag("mytag") 

To get data

+5
source

I found limitations with TagService and used the following to get a list of tags from a specific set of nodes. Just a request for group tags didn’t work for me.

 var pages = parentpage.Children; var allNodesWithTags = pages.Where("tags != \"\""); List<string> taglist = new List<string>(); foreach (var node in allNodesWithTags) { taglist.AddRange(node.tags.ToString().Split(',')); } taglist = taglist.OrderBy(q => q).ToList(); 

Then simply list the tags from the child nodes:

 @foreach (string tag in taglist.Distinct()) { <li><a href="#" class="">@tag</a></li> } 
+1
source

Source: https://habr.com/ru/post/984423/


All Articles