Author Information for Blog

Dcode warner asked on March 12, 2017 20:43

How can I include the name of the person who posted a blog post that displays their 'name' and a brief 'bio' after the post entry. And a link that 'show other other posts by the author'.

Correct Answer

Mariia Hrytsai answered on March 15, 2017 10:28

I am not sure it is good to hardcode IDs. But still code above will work. Another question how you are going to tie blog post and author? Will author be as a parent page for blog posts? If so, you can use something like this {%CurrentDocument.Parent.position|(identity)GlobalAdministrator%}

2 votesVote for this answer Unmark Correct answer

Recent Answers


Mariia Hrytsai answered on March 13, 2017 11:21 (last edited on December 10, 2019 02:30)

First of all you should store your blog post author user ID in NodeOwner column. In Kentico interface you can go to Properties -> General tab and set the Owner. Here are multiple ways to display the NodeOwner information on the blog post.

  • If you display author information in blog posts listing you can use macros to display author full name and bio. For full name use Kentico macro <%#GetUserFullName(Eval<int>("NodeOwner"))%> and for bio you might need to write your custom transformation method that will return the information for example from CMS_UserSettings table UserDescription column. Method will recieve NodeOwner ID and will do something like this
public string GetUserBio(int userId)
{
      UserInfo user = UserInfoProvider.GetUserInfo(userId);
      if(user!=null)
      {
         return user.UserDescription;
      }
      
      return "";
}

This also will work for blog post details page, if you are using some listing web part with listing transformation and selected item transformation.

  • The other possible way to display author information on blog post details page to use some additional web part that will display user info in transformation. It might some repeater or user listing with where condition 'UserID = {%CurrentDocument.NodeOwner|(identity)GlobalAdministrator%}

    And you link will look like following: <a href="/Blogs?author="<%#Eval("NodeOwner")%>>show other other posts by the author</a>

    Or please check how to use wildcard urls for that https://docs.kentico.com/k8/configuring-kentico/configuring-page-urls/wildcard-urls. It will make your url more elegant:)

    It might a little bit different from scenario you have, but I hope you have got main idea how to deal with that.

3 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 13, 2017 17:30

Thanks fro pointing me in the right direction

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 14, 2017 15:48 (last edited on December 10, 2019 02:30)

Another question. Sorry. What if I have an idea to create a separate doc type with the author, bio and position and get the field values from there:

Example:

Column name: postedbyPosition1

Then I say something like:

{% if (CurrentDocument.NodeOwner == 811) { return " + postedbyPosition1 +" } else return { "" } |(identity)GlobalAdministrator%}

Can I write it like this? Is the script above correct?

1 votesVote for this answer Mark as a Correct answer

Dcode warner answered on March 15, 2017 15:35

Your right. I came to that same conclusion. There isn't a way to connect them both.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.