get list of tags having atleast one blogpost associated with

Posted by Community Admin on 04-Aug-2018 13:42

get list of tags having atleast one blogpost associated with it......

All Replies

Posted by Community Admin on 27-Mar-2014 00:00

How to get all tags that have atleast one blogpost associated with it.

 The following line, gets me all tags, irrespective of whether there exists a blogpost associated with it.

Taxonomy ht = tManager.GetTaxonomies<Taxonomy>().Where(t => t.Name == this.Tags_ClassificationName.ToLower().Replace(" ", "-")).SingleOrDefault();

 Need some  help in filtering the tags to get only ones that are associated to blogposts.

Posted by Community Admin on 27-Mar-2014 00:00

There's a taxonomy statistics table which should give you what you're looking for (custom query)

Looks like there's a GetStatistics method on the TaxonomyManager, haven't tried it, but maybe checkout the table and start there.

Posted by Community Admin on 27-Mar-2014 00:00

Hello Steve,

 Thanks for your reply. I tried in that route, and seems like this is going to work, but I am not able to get the name/text of the tag that matches the filter. Can you suggest a workaround for this.

 var tManager = TaxonomyManager.GetManager();
            Taxonomy ht = tManager.GetTaxonomies<Taxonomy>().Where(t => t.Name == this.Tags_ClassificationName.ToLower().Replace(" ", "-")).SingleOrDefault();

            if (ht != null)
           

//code that gets the statistics
                List<TaxonomyStatistic> newlist = tManager.GetStatistics().Where(t => t.TaxonomyId == ht.Id && t.DataItemType == "Telerik.Sitefinity.Blogs.Model.BlogPost" && t.MarkedItemsCount > 0).ToList();
                
                foreach (TaxonomyStatistic ts in newlist)
               
                    //Response.Write("count is : " + ts.MarkedItemsCount+ " and ID is : " + ts.Id +"<br>");
               
           

 

when I do "ts." in the above code. I dont have the name property.

Thanks,

 Phani.

Posted by Community Admin on 27-Mar-2014 00:00

First off, see if you can kill the .ToList(), it throws the data into memory.

Second maybe just add a a function to lookup the taxa with the manager and return it's name

 var taxa = this.GetTaxa(ts);
if(taxa != null)
    Debug.WriteLine("Taxa is 0".Arrange(taxa.Title));

 

 ...is that what you're asking?

This thread is closed