Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Filtering Blog entries by tag

Vote:
 

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

#41949
Aug 04, 2010 15:29
Vote:
 

Is this related to the Blog templates in EPiServer demo package or EPiServer Community?

#41963
Aug 05, 2010 9:50
Vote:
 

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.

 

#41968
Aug 05, 2010 11:10
Vote:
 

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

#43082
Sep 13, 2010 14:11
Vote:
 

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

#44108
Edited, Sep 30, 2010 21:43
Vote:
 

Thanks. Just what I was looking for.Works like a charm.

 

Kind Regards

Sandeep

#51519
Jun 12, 2011 14:40
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.