More in this section

Forums / Developing with Sitefinity / How to retrieve blog author.

How to retrieve blog author.

13 posts, 0 answered
  1. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    16 Oct 2009
    Link to this post
    I am wanting to get the full name of the person who wrote a blog post.
    And I am NOT referring to the blogs owner, I can get to it.

    TIA
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    16 Oct 2009
    Link to this post
    Hello Rob Gaudet,

    Thank you for using our services.

    Blog posts are of type Telerik.Cms.Engine.IContent which type does not store owner data. However I can suggest an alternative approach on how you can track who is creating a blog post through the metafields. Take a look at the code bellow that can be added to the Global.asax file, this code will modify the author field of each blog post so it reflects the userName of the user that has created it:
    void Application_Start(object sender, EventArgs e)
      {
          // Code that runs on application startup
     
          Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing);
     }
      void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)
      {
          Telerik.Cms.Engine.IContent cnt= (Telerik.Cms.Engine.IContent) e.CommandArguments ;
          if (e.CommandName == "CreateContent" && cnt.ProviderName=="Blogs")
          {
              cnt.SetMetaData("Author", Telerik.Security.UserManager.Default.GetUser().UserName);
          }
      }

    Then add a not visible label to the external templates for creating and editing blog posts. Files located at ~/Sitefinity/Admin/ControlTemplates/Blogs/, edit the PostEdit.ascx and PostNew.ascx by adding:
    <sf:ContentMetaFields ID="MetaFields" runat="server">
                       <ItemTemplate>
                           <h3>
                               <asp:Literal ID="Literal13" runat="server" Text="<%$Resources:Category %>"></asp:Literal></h3>
                           <fieldset class="set">
                               <ol class="setIn clearfix">
                                   <asp:Literal ID="Author" runat="server" Visible="false" />

    Then map those templates and restart the website. Then you will be able to get the name of the author that has created the blog post with the GetMetaData() method.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    16 Oct 2009
    Link to this post
    Radoslav,

    I am missing the PostEdit.ascx and PostNew.ascx files. I have only a ContentVersionNew.aspx file in  ~/Sitefinity/Admin/ControlTemplates/Blogs/

    I have version 3.7.2022.3.

    Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 Oct 2009
    Link to this post
    Hello Rob Gaudet,

    Please take a look at the following article that describes from where and how you can obtain the templates - How to map a view to an external template, in Sitefinity 3.6 or later?

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    28 Oct 2009
    Link to this post
    What I need to do is show the Blog Author on the public side, not on the edit or new side of a template.

    How can I show the person that is associated with a blog post, not the person who is associated with the blog?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Oct 2009
    Link to this post
    Hello Rob Gaudet,

    Generally you have a blog. The blog has author. All post in this blog are created by the blog author. This is how we use our blogs at http://www.sitefinity.com/blogs.aspx.
    If you want to set author per post you need to map PostNewView and PostEditView templates, then create a new metakey and use it for post author. Afterwords you need to map ListPageMaster and ListPageDetails for BlogPosts control and add reference to the newly created metakey.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    29 Oct 2009
    Link to this post
    How can I retrieve a users full name from their profile instead of just their username?
  8. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    29 Oct 2009
    Link to this post
    How about this?

        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup

            Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing);
        }

        void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)
        {
            Telerik.Cms.Engine.IContent cnt = (Telerik.Cms.Engine.IContent)e.CommandArguments;
            if (e.CommandName == "CreateContent" && cnt.ProviderName == "Blogs")
            {
                string username = Telerik.Security.UserManager.Default.GetUser().UserName;
                ProfileBase profile = ProfileBase.Create(username, true);
                string firstname = profile.GetPropertyValue("FirstName").ToString();
                string lastname = profile.GetPropertyValue("LastName").ToString();
                cnt.SetMetaData("Author", firstname + " " + lastname);

            }
        }
  9. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    30 Oct 2009
    Link to this post
    How do I get the Authors name on the page?

    Is the name on the post or the blog?


        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            BlogManager manager = new BlogManager();

            IList posts = manager.Content.GetContent();

            if (posts.Count > 0)
            {
                sb.Append("<ul class=\"recent\">");

                for (int i = 0; i <= NumberOfBlogs; i++)
                {
                    if (posts.Count < (i + 1)) break;

                    IContent item = (IContent)posts[i];

                    IBlog blog = manager.GetBlog(item.ParentID);

                    sb.Append("<li>");
                    sb.Append("<a href=\"" + GetUrl(blog.BlogPage.Replace(".aspx", "/") + item.UrlWithExtension) + "\">");
                    sb.Append(item.GetMetaData("Author").ToString());
                    sb.Append("</a>");
                    sb.Append("</li>");
                }

                sb.Append("</ul>");
                literal.Text = sb.ToString();
            }
        }
  10. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    30 Oct 2009
    Link to this post


    What I ultimately need to do ultimately is get a list of post authors and link to a profile for the author.

    Yes a blog has an author associated with it, but multiple users are posting to the blog. I want to display a list of all users who post to blogs with a link to all of their blog posts.

    Perhaps I should just return a list of all users and use that?
  11. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    30 Oct 2009
    Link to this post
    Okay...

    Current situation.

    How do I change a value in a template? Such as author?

    Currently the blog author is appearing, instead, I need the post author to appear.
    http://www.newpatriotjournal.com/ContractFromAmericaBlog.aspx
  12. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    30 Oct 2009
    Link to this post
    Hello Rob Gaudet,

    In the external templates for blog post control ContentViewItemList.ascx and ContentViewSingleItem.ascx add the respective code snippets for retrieving the metafield information from the blog post.
    ContentViewItemList.ascx:
    <script type="text/C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            repeater.ItemDataBound+=new RepeaterItemEventHandler(repeater_ItemDataBound);
        }
        void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Literal title = (Literal)e.Item.FindControl("Title");
                Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager();
                foreach (Telerik.Cms.Engine.IContent blogPost in blogManager.Content.GetContent())
                {
                    if (blogPost.GetMetaData("Title").ToString() == title.Text)
                    {
                        Literal author = (Literal)e.Item.FindControl("Author");
                        author.Text = blogPost.GetMetaData("Author").ToString();
                        break;
                    
                }
            }
        }
        </script>

    ContentViewSingleItem.ascx:
    <script type="text/C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
                 Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager();
                foreach (Telerik.Cms.Engine.IContent blogPost in blogManager.Content.GetContent())
                {
                    if (blogPost.GetMetaData("Title").ToString() == this.Title.Text)
                    {
                        this.Author.Text = blogPost.GetMetaData("Author").ToString();
                        break;
                    }
                }
            }
        }
        </script>


    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  13. Rob Gaudet
    Rob Gaudet avatar
    16 posts
    Registered:
    27 Nov 2005
    30 Oct 2009
    Link to this post
    Yes that worked Radoslav. Thanks.
Register for webinar
13 posts, 0 answered