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

Forums / Designing with Sitefinity / BlogPost FilterExpression by category

BlogPost FilterExpression by category

6 posts, 0 answered
  1. Biren
    Biren avatar
    23 posts
    Registered:
    02 Nov 2010
    08 Dec 2010
    Link to this post
    Hi,
    I want to filter blog posts based on the category of current blog. I saw few other posts where suggested expression is like,
    Publication_Date <=
    "#now" AND Expiration_Date > "#now" AND Category = "dev"

    But this will still get blogs under category "dev", is there a way to dynamically find the category of current blog like finding time by "#now" ?

    or can we do this in code behind,
    i can specify FilterExpression by Telerik.Blog.WebControls.BlogPosts.FilterExpression = "Category = 'Sports'" and then reload the base.
  2. Biren
    Biren avatar
    23 posts
    Registered:
    02 Nov 2010
    10 Dec 2010
    Link to this post
    Can someone please reply.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Dec 2010
    Link to this post
    Hello Biren,

    The blog itself does not have a category. Category is a metakey that can be set for a post. To get the category for a blog post you should use GetMetaData of the IContent object ( the post)

    The BlogPosts can be filtered dynamically by creating a custom class that inherits from it. Inside CreateChildControls you can use ContentFilterBuilder before calling the base.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Biren
    Biren avatar
    23 posts
    Registered:
    02 Nov 2010
    11 Dec 2010
    Link to this post
    Hi Ivan,
    Thanks for your reply. Here is the scenario that i am trying to achieve. I have a page with list of blog. With "Full Story" link to display full content of each post [List & Page option].  When user clicks on Full Story link, on the detail page i want to get all blog posts with same category as of current post. When i am on detail page, how i can get category info for the current post.

    I tried code below and it worked as i wanted. But i had to hard code the category value. Is there a way to get the category of current post before setting the filter & calling CreateChildControls() method ?

    ContentFilterBuilder builder = new ContentFilterBuilder(this);
    builder.AddFilter(new ContentFilterStatement("Category", "Fasion", ContentFilter.Condition.In, ContentFilter.JoinType.And));
    base.CreateChildControls();

    Regards,
    Biren
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Dec 2010
    Link to this post
    Hello Biren,

    Ok. Here is what you have to do.

    1. Get the current item from the QueryString
    2. Get the item category
    3. Get all items from a category

    var Manager = newContentManager("Blogs");
    if(Context.Items.Contains(Manager.Provider.ContentItemKey))
    itemId = (Guid)((IUrlRewriteData)Context.Items[Manager.Provider.ContentItemKey]).Data;
    ...
    ....
     
    var cntItem = Manager.GetContent(itemId);
    var category = cntItem.GetMetaData("Category");
     
    ...
     
     // get all items from this category and list them


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Biren
    Biren avatar
    23 posts
    Registered:
    02 Nov 2010
    13 Dec 2010
    Link to this post
    Thanks Ivan. This is the code I am using and it works well :).
     
    protected override void CreateChildControls()
            {
                if (base.Context.Items.Contains(base.Manager.Provider.ContentItemKey))
                {
                    Guid itemguid = (Guid)((IUrlRewriteData)base.Context.Items[base.Manager.Provider.ContentItemKey]).Data;
                    IContent currentContent = base.Manager.GetContent(itemguid);
                    string category = currentContent.GetMetaData("Category") as string;
                    if (!string.IsNullOrEmpty(category))
                    {
                        ContentFilterBuilder builder = new ContentFilterBuilder(this);
                        builder.AddFilter(new ContentFilterStatement("Category", category, ContentFilter.Condition.In, ContentFilter.JoinType.And));
                    }
                }
                base.CreateChildControls();
            } 
Register for webinar
6 posts, 0 answered