+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / get list of tags having atleast one blogpost associated with it......

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

4 posts, 0 answered
  1. Phani
    Phani avatar
    9 posts
    Registered:
    18 Mar 2014
    27 Mar 2014
    Link to this post

    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.

  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    27 Mar 2014 in reply to Phani
    Link to this post

    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.

  3. Phani
    Phani avatar
    9 posts
    Registered:
    18 Mar 2014
    27 Mar 2014 in reply to Steve
    Link to this post

    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.

  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    27 Mar 2014 in reply to Phani
    Link to this post

    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?

4 posts, 0 answered