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

Forums / Deployment / Using View Count

Using View Count

4 posts, 0 answered
  1. Paul N
    Paul N avatar
    55 posts
    Registered:
    24 Apr 2010
    10 Sep 2010
    Link to this post
    Hi,

    Recently I discovered how to create a blog posts item filtered by View Count (this is the view count that is displayed on the individual posts inside of sitefinity), so that it showed the most viewed posts on top. - this was using the sort expression "View_Count DESC". But I was wondering if I could use this on the blog content view single item template to display the view count for that post to the public. What I tried below doesn't seem to be working:

    <asp:Literal ID="View_Count" runat="server" Text="View Count:"></asp:Literal>

    Can this be done easily? I thought maybe I just had the ID wrong.

    Also I was wondering where the view count statistics come from, as I always get more views on the blog posts than what the Google analytics show.

    Thanks,
    Paul N
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    10 Sep 2010
    Link to this post
    Hi Paul N,

    Thank you for using our services.

    Can you try with something like the snippet bellow:
    <p>
        <asp:Label ID="lbl" runat="server" AssociatedControlID="View_Count" Text="View Count: "></asp:Label>
        <asp:Literal ID="View_Count" runat="server"></asp:Literal>
    </p>

    The problem appears to be that you are presetting the text of the literal which should display the view count.

    Best wishes,
    Radoslav Georgiev
    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
  3. Paul N
    Paul N avatar
    55 posts
    Registered:
    24 Apr 2010
    10 Sep 2010
    Link to this post
    Hi Radoslav Georgiev,

    Thank you for responding.

    I tried using that code you provided, it shows the label "View Count: ", same as what mine did, but still isn't showing the actual number.

    Is the ID "View_Count" right?

    Thanks,
    Paul N
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Sep 2010
    Link to this post
    Hello Paul N,

    The problem is that ContentView shows only the following types of metakeys

    ShortText
    LongText
    DateTime

    You could create a custom control that inherits from ContentView and implement the support for the other types by overriding SetItemMetaData

    sample

    protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
    {
        base.SetItemMetadata(itemContainer, contentItem);
      
           object obj;
           foreach (IMetaInfo info in Manager.MetaKeys.Values)
           {
               Control ctrl = FindContentViewControl(info.Key, itemContainer);
      
               if (info.ValueType == MetaValueTypes.Integer)
               {
                   if (ctrl is ITextControl)
                   {
                       obj = contentItem.GetMetaData(info.Key);
                       if (obj != null)
                       {
                           ((ITextControl)ctrl).Text = (string)obj;
                       }
                   }
               }
           }
    }

    another option is using a metakey of type ShortText and the convert it to int



    Kind regards,
    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
Register for webinar
4 posts, 0 answered