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 Zhokh 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%}

0 votesVote for this answer Unmark Correct answer

Recent Answers

Mariia Zhokh answered on March 13, 2017 11:21 (last edited on March 13, 2017 11:22)

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);
         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%}'. This will allow to display information about only one user and only on blog post page itself.

To display link to other blog posts by this user you might setup wildcard url or use query parameter for your main blog posts listing page. And if query parameter is set add the Where condition to blog posts listing web part:

{%(!String.IsNullOrEmpty( ?  String.FormatString("[NodeOwner] = '{0}'",SQLEscape(QueryString.GetValue("author", ""))): "" #%}

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 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.

2 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

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:


Column name: postedbyPosition1

Then I say something like:

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

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.