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

Forums / Developing with Sitefinity / Filter BlogPost Display

Filter BlogPost Display

5 posts, 0 answered
  1. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    23 Mar 2009
    Link to this post
    How would I be able to filter out the posts that I only want to be displayed in the blogpost control. For example post that only belongs to a certain blog, or filter by category, author, etc. How would I be able to accomplish this?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Mar 2009
    Link to this post
    Hello Roland,

    You can use FilterExpression property under advanced tab of the control. You can filter by metafileds - this is the allowed operands.

    Some examples.

    Title = "MyPostTitle"
    Tag.Name = "MyTag"

    Here is an example that demonstrates programmatically creating of an filter.

            BlogManager blogManager = new BlogManager("Blogs"); 
            // you can get the blog posts directly passing the ID of the blog 
            //check out the other parameters for this method 
            IList listofAllBlogs = blogManager.GetBlogs(); 
            foreach (IBlog blog in listofAllBlogs) 
            { 
                if (blog.Name == "Myblog"
                { 
                    Guid parentId = blog.ID; 
                    // here we can add filter expression as well - MetaSearchInfo filter 
                    // or ContentFilterBuilder 
                    string catid = "category"
                    ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this); 
                    filterBuilder.AddFilter(new ContentFilterStatement("Category.ID", catid.ToString(), ContentFilter.Condition.Equal, ContentFilter.JoinType.And)); 
     
                    IList listofPosts = blogManager.GetPosts(string.Empty, filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter()); 
                    foreach (IContent post in listofPosts) 
                    { 
                        Response.Write(post.Content + "<br />"); 
                    } 
                } 

    For more information, please check out the API.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    24 Mar 2009
    Link to this post
    Does this mean that I have to create a custom control?
  4. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    24 Mar 2009
    Link to this post
    Follow up..What I really wanted to happen is that on the page load event I want to be able to access the blogpost control programmatically and then set its filter expression. How will I be able to do that?
  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    24 Mar 2009
    Link to this post
    Hello Roland,

    Here is an example how to get all BlogPosts controls on the current page and set their FilterExpression property:

    protected void Page_Load(object sender, EventArgs e) 
        { 
            CmsManager manager = new CmsManager(); 
            ICmsUrlContext context = CmsUrlContext.Current; 
            IPage page = manager.GetPage(context.PageID); 
     
            foreach (ICmsWebControl control in page.Controls) 
            { 
                if (control.ControlType.FullName == typeof(Telerik.Blogs.WebControls.BlogPosts).FullName) 
                { 
                    Telerik.Blogs.WebControls.BlogPosts webControl = control.LoadControl(thisas Telerik.Blogs.WebControls.BlogPosts; 
                    if (webControl != null
                    { 
                        webControl.FilterExpression = "Title = MyPost"
                    } 
                } 
            }  
        } 

    You could implement this functionality either in the master page or in a user control depending on the specific case.

    Hope this helps.

    All the best,
    Pepi
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Register for webinar
5 posts, 0 answered