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

Forums / Designing with Sitefinity / How to display name of blog post author

How to display name of blog post author

5 posts, 0 answered
  1. Chris
    Chris avatar
    9 posts
    Registered:
    25 Sep 2008
    12 Nov 2008
    Link to this post
    Hi,

    This might have been asked before but I can't find anything when I search the forums...

    How can I display the name of the Sitefinity user who posted the blog article on the article detail page.

    I know there is an "Author" textbox when you create a blog, but I don't understand the point of this, since all my blogs have many different authors.  I just want to display the name of the individual who wrote that specific blog post.

    I'd be grateful if anyone can help!

    Chris
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Nov 2008
    Link to this post
    Hi Chris,

    There is a Author field and you can use it in case you have several bloggers. In other words, every blog owner will have its own blog. Such is the case in ours blogs.telerik.com web site for example. If the author field is empty, then the username will be submitted as author name.

    If you want to use only one blog for all of your users, you should do some custom implementations:
    1. In your global.asax file, subscribe to ContentManager_Executing event, in the Application_Start():
        void Application_Start(object sender, EventArgs e)  
        { 
           Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing); 
        } 

    2. Use the following code in the event body:
     
        void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e) 
        { 
            //Check whether the user is creating content 
            if (e.CommandName == "CreateContent"
            { 
                //take the IContent Item from the command arguments 
                Telerik.Cms.Engine.IContent cnt = e.CommandArguments as Telerik.Cms.Engine.IContent; 
                //chech if there is such content and if it belongs to the Blogs provider 
                if (cnt != null && cnt.ProviderName == "Blogs"
                { 
                    //get the current user's First and Last names 
                    ProfileBase profile = ProfileBase.Create(HttpContext.Current.User.Identity.Name); 
                    string FirstName = profile.GetPropertyValue("FirstName").ToString(); 
                    string LastName = profile.GetPropertyValue("LastName").ToString(); 
                    //Save these to the Author Metafield. 
                    cnt.SetMetaData("Author", FirstName+" "+ LastName); 
                } 
            } 
        } 

    That is all. Now, every time when someone is creating a content (a blog post), the Author field will be populated with the user's First and Last name. Please note that the user should have first and last name defined in his profile (Personalization Options for this user).

    I hope this helps.

    Kind regards,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Chris
    Chris avatar
    9 posts
    Registered:
    25 Sep 2008
    12 Nov 2008
    Link to this post
    Thanks Georgi.

    I continue to be impressed by the speed and quality of Terlik's technical support!

    Chris
  4. ddblee
    ddblee avatar
    20 posts
    Registered:
    24 Jul 2008
    25 Nov 2008
    Link to this post
    How would someone then:
    • build a list of blog authors from this metafield
    • retrieve all blog posts from a single author

    Thanks!
  5. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    26 Nov 2008
    Link to this post
    Hello ddblee,

    1. Build a list of blog authors from this metafield

    You need to iterate through all blog posts. For each blog you should take the Author name, which in this case is stored in metafield. This can be done with GetMetaData method:
    strAuthor = blogPost.GetMetaData("Author"); 
    You can store this authors in a list, and display only the unique entries.

    2. Retrieve all blog posts from a single author
    Since you will have the blog authors from the first example, you can again Get all posts, then while iterating through the collection, you show the ones which belong to your author. You should again use the GetMetaData method to get the current item's author, and check whether this is the author you are looking for.

    Let us know if you have any other questions.

    Best wishes,
    Georgi
    the Telerik team

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