Display author of current post on single template

Hi,

I am trying to display author of current post on a single, with link to author profile and it’s just showing the author id and url to the same post I am viewing. So I don’t think I have the field setup right, I’m trying something like this:

<a href="{Field url}"><Field author /></a>

Do I need to use User fields, as opposed to post fields? Any insights would be appreciated. Thanks!

I’m not sure if your markup is inside a loop or not, but if it’s not and you’ve got it displaying on a single post page, then L&L would just be taking the fields from the current posts, just as if it was in a post loop That means that in your case, Field url would refer to the URL of the current post, not the post archive URL.

Your intuition was totally correct that you’d need to be working with a User loop so that you can reference user-specific fields like the user’s post archive URL (which is Field archive_url). If you’re curious why you’d need to create a loop to give L&L some context about where to look for the post archive URL data, you can check out this comment I made for someone with a similar question.

So if I understand correctly, you’d need to create a user loop that only loops through the user that wrote the current post (whatever post your L&L markup gets placed on). You could pass the author field from the current post to the id parameter of a user loop. Sorry if that sounds like word salad! In practice it’s pretty simple and would look something like this:

<Loop type=user id="{Field author}">
  <a href="{Field archive_url}"><Field full_name /></a>
</Loop>

Hope that helps!

1 Like

Thanks @benjamin that’s it. I really appreciate your help.

1 Like

I believe it’s possible to create a user loop directly from the post field author.

<Loop field=author>
  ...
</Loop>

Yes, this works too. I did something like this:

<Loop field=author>
  <a href="{Field archive_url}"><Field display_name /></a>
</Loop>

The initial suggestion also worked and adding for reference here too.

<Loop type=user id="{Field author}">
        <a href="{Field archive_url}"><Field display_name /></a>
</Loop>
1 Like