More in this section
Forums / Developing with Sitefinity / Access to Blog Post Categories

Access to Blog Post Categories

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
6 posts, 1 answered
  1. Todd
    Todd avatar
    6 posts
    Registered:
    03 Aug 2011
    15 Aug 2011
    Link to this post
    I am looking for a way with the api to access a Blog Post Categories. I have a top level MasterPage that shows the same header and footer throughout the site. In the footer I need to show the title of the most recent blog post (which I was able to do through the API). This also needs to be a link to a details page with a url in this format:
    /{blog name}/{top category name}/{bottom category name}/details?id={blog id}.
    The details page will have a blog details layout and codefile that will process the id to set the RadListView DataSource. 

    Is there a way to find out the category structure of a specific blog post to properly form the url?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Aug 2011
    Link to this post
    Hello Todd,

    If you have the blog post ID you can the the BlogPost object and
    call blogpost.GetValue("Category") or
    var propDesc = OrganizerBase.GetProperty(dataItem.GetType(), "Category") as TaxonomyPropertyDescriptor;

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Todd
    Todd avatar
    6 posts
    Registered:
    03 Aug 2011
    17 Aug 2011
    Link to this post
    I got the blog post using:
    var manager = BlogsManager.GetManager();
    var allPosts = manager.GetBlogs().Where(p => p.Title == "Broan Pro").First().BlogPosts;
    var post = allPosts.Where(p=>p.Status==ContentLifecycleStatus.Live).OrderByDescending(p => p.PublicationDate).First()

    but post does not have a GetValue() method. Post has a type of Telerik.Sitefinity.Blogs.Model.BlogPost

    For the second way you showed I am unsure what the dataItem type should be. I tried 
    var propDesc = OrganizerBase.GetProperty(typeof (Telerik.Sitefinity.Blogs.Model.BlogPost), "Category") as TaxonomyPropertyDescriptor;
     
    but I wasn't sure where to go from there. I tried to call the GetValue method with the parameter being the BlogPost that I need the categories for but this didn't seem to give what I needed.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Aug 2011
    Link to this post
    Hi Todd,

    When you use GetValue you need to pass as a parameter the property you are looking for - "Category". This should returned TrackedList of guids - the ids of the categories.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Kalyani
    Kalyani avatar
    1 posts
    Registered:
    30 Sep 2014
    02 Apr 2015
    Link to this post
    Is it possible to retrieve Newsitem based on Taxonomy like the blogpost, as u mentioned here
  6. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    06 Sep 2017
    06 Apr 2015
    Link to this post
    Hi Kalyani,

    You can try this approach:
    Add the following using:
    using Telerik.Sitefinity.Data.Linq.Dynamic;

    and filter the NewsItems by the following sample code:
    var catName = "MyCategoryName";
    var manager = TaxonomyManager.GetManager();
    var categoriesTaxonomy = manager.GetTaxonomy<HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId);
    var category = categoriesTaxonomy.Taxa.Where(t => t.Title == catName).FirstOrDefault();
     
    var nm = NewsManager.GetManager();
    var filteredNewsItems = nm.GetNewsItems().Where("Category.Contains((" + category.Id.ToString() + ")) && Status=\"Live\"");

    I hope this helps.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
6 posts, 1 answered