More in this section

Forums / Developing with Sitefinity / Blog View Count does not count

Blog View Count does not count

3 posts, 0 answered
  1. Steve
    Steve avatar
    11 posts
    Registered:
    18 Dec 2008
    20 Mar 2009
    Link to this post
    Hello - we have encorporated a Blog into our web-site.  Unfortunately I am told that readers some times read the blog, but the 'Blog View Count' in the administrator console always reports 0 views.  Have we set this up incorrectly, or does this feature not work?

    Thanks for any hint,
    Steve
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    20 Mar 2009
    Link to this post
    Hi Steve,

    This functionality is still not finished. You could extend your controls though, in order to take advantage of the View_Count metafield:
    You need to make the following changes in order to fix your custom control:

    1. Create a custom control, inheriting from BlogPosts. This should be a class in the App_Code directory:
    .cs
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Telerik.Blogs.WebControls; 
    using Telerik.Blogs; 
    using Telerik.Cms.Engine; 
    using Telerik.Cms.Web; 
     
    namespace Telerik.Blogs.WebControls 
        public class BlogPostUpdate : BlogPosts 
        { 
            protected override void Render(System.Web.UI.HtmlTextWriter writer) 
            { 
                base.Render(writer); 
     
                if (!(this.Page is EditPage) && !(this.Page is PreviewPage) && this.itemId != Guid.Empty) 
                { 
                    IContent post = base.Manager.GetContent(this.itemId); 
                    long postViews = 0; 
     
                    if (post != null
                    { 
                        object o = post.GetMetaData("View_Count"); 
                        if (o != null
                            postViews = (long)o; 
                             
                        postViews++; 
     
                        post.SetMetaData("View_Count", postViews); 
                        manager.SaveContent(post); 
                    } 
                } 
            } 
        } 
     

    Also, you need to register the newly created control in the <toolboxControls> section of the web.config file to display it in "Add Controls" toolbox:

    <add name="BlogPostUpdate" section="Blogs" type="Telerik.Blogs.WebControls.BlogPostUpdate, App_Code" /> 

    Then, you should use the new control for your pages.

    Do let us know if this helps.


    Kind regards,
    Georgi
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    20 Mar 2009
    Link to this post
    Hello Steve,

    Here is just a quick follow up. In Sitefinity 3.6 we have introduced the embedded templates. When you override the control, you should specify the templates that should be used, otherwise you will get an error. Please take a look at the article Extending ContentView controls for more information(part4) on how to specify the templates.

    Greetings,
    Georgi
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
3 posts, 0 answered