How to display author name in blog posts?

Topics: Customizing Orchard, General, Writing themes
Feb 1, 2012 at 5:03 AM

Hi,

I've looked for the answer to this everywhere but sadly I couldn't find anything. Basically I need to know if there is any code that would display the name of the user who made a blog entry and where to put it.

My website is http://www.ultrasoundlink.net/ (I made it for a client) and while I found a cheat way of putting in the main user's name when you click on the blog entries by putting in a line of html code into Themes>Contoso>Views>Content.cshtml this obviously doesn't work if there are multiple registered users who can make posts as it only displays the name I wrote down in my little line of code.

Any ideas? Thanks!

Coordinator
Feb 1, 2012 at 8:32 AM

placement.info for the common part, plus some usage of Shape Tracing's Model tab should get you there.

Feb 2, 2012 at 10:06 PM

Thank you for that module, I found where to place code for displaying author name thanks to it but I couldn't find what code to use to display author's name. This is the code it uses for date and time the blog post was published:

<div class="published">@Display.PublishedState(createdDateTimeUtc: Model.ContentPart.CreatedUtc, publisheddateTimeUtc: Model.ContentPart.PublishedUtc)</div>

I've only ever worked in HTML and CSS so I know very little about CMS customization apart from editing the way certain things look, sorry for the trouble.

Feb 2, 2012 at 10:10 PM
Edited Feb 2, 2012 at 10:27 PM

Nevermind, I found a way to do it, woohoo! :D

 

In case this helps someone in the future the code to put down to display author name is:

<div class="authorname"><p>By: @Model.ContentPart.Owner.UserName</p></div>

Sep 6, 2013 at 11:09 PM
bertrandleroy wrote:
placement.info for the common part, plus some usage of Shape Tracing's Model tab should get you there.
what kind of help is this?!?

how are you supposed to be looking for an element with shape tracing when the element you are looking for is not beeing displayed?!

and "placement.info for the common part" - what does that mean? What am I supposed to look for?

Shaking head in annoyence!
Coordinator
Sep 7, 2013 at 12:40 AM
Sorry for trying to help and for not being in front of your monitor. What exactly are you complaining about? You're not even the person who asked the question. Gee. Also, the author of the original question is giving you a very explicit solution. What's your problem, seriously?
Sep 7, 2013 at 9:46 AM
Sry, it was late and I have been trying to find a solution following your not very explicit advice for over an hour.

Sry for the language - I was just a bit annoyed.

Anyway, I was trying to do it via the placement.info as you suggested. However I could not find the correct code to include.

I was looking for something similar to:

<Place Parts_Comments_Count="Content:after" />

that I could put in my placement.info - as you suggested. However I could not find the correct code to display the author of a blog post.

So, pls ignore my rude comment from before.
Coordinator
Sep 7, 2013 at 10:59 PM
Sure, no problem.
Sep 8, 2013 at 4:55 PM
So is there any way to display the blog post author name by using the placement.info file?
Coordinator
Sep 8, 2013 at 7:55 PM
Yes, you need to make sure that the shape where you want the author to be rendered (typically Parts_Common_Metadata or Part_Common_Metadata_Summary) is included by placement into a zone that exists in content.cshtml, then you need to add the rendering code for the property (@Model.ContentPart.Owner.UserName here) into that template (you can discover the expression for the property using the Model tab of shape tracing).
Apr 17, 2015 at 6:50 PM
Edited Apr 17, 2015 at 6:51 PM
Hey Wota,

It's been two years, but if you haven't solved the problem here's what I'm using to get the author from the content model.
if(Model.ContentItem.BlogPostPart != null && Model.ContentItem.BlogPostPart.Creator != null) {
       postAuthor = Model.ContentItem.BlogPostPart.Creator.UserName;
}