November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Is this related to the Blog templates in EPiServer demo package or EPiServer Community?
We are using Relate+ and CMS 5. What I am looking for is a code sample for how I can filter out all entries for a certain blog object with a certain tag name.
Does anyone know how to solve this? The documentation states to use TagHandler.Instance.GetTaggedItems but there is no Instance member variable in TagHandler and the GetTaggedItems is declared as internal.
Please advise.
Best Regards,
Tobias Jakobsson
Finally have a solution for this. Below is a code example of a function that finds entries in a blog with a specified tag:
public static EntryCollection GetEntriesByTag(Blog blog, string tagString, int page, int pageSize, out int totalItems)
{
EntryQuery entryQuery = new EntryQuery();
entryQuery.Blog = new BlogCriterion();
entryQuery.Blog.ID = new IntegerCriterion();
entryQuery.Blog.ID.Value = blog.ID;
// Create a TagCriterion
TagCriterion tagCrit = new TagCriterion();
tagCrit.Name = new StringCriterion();
tagCrit.Name.Includes = new StringInCriterion();
tagCrit.Name.Includes.Values.Add(tagString);
// Create a entityTagCriterion, and use the TagCriterion created
EntityTagCriterion entityTagCriterion = new EntityTagCriterion();
entityTagCriterion.Tag = tagCrit;
// Finally, set the Tags property
entryQuery.Tags = new TagCollectionCriterion();
entryQuery.Tags.Containing = new MultipleEntityTagCriterion();
entryQuery.Tags.Containing.AddTag(entityTagCriterion);
entryQuery.Created = new DateTimeCriterion();
entryQuery.OrderBy.Add(new CriterionSortOrder(entryQuery.Created, SortingDirection.Descending));
EntryCollection entries = BlogHandler.GetQueryResult(entryQuery, page, pageSize, out totalItems);
return entries;
}
What was a bit tricky to figure out was that you should use both TagCriterion and EntityTagCriterion, and how these correlate.
Happy coding!
// Regards, Torbjörn Stavås
Thanks. Just what I was looking for.Works like a charm.
Kind Regards
Sandeep
Hi
I want to be able to filter blog entries by tag but cant figure out how. I can see that there is something called TagCriterion that could be used. If so, how?
Thanks