How to get author's name and image of the blog post published

Hi there, referring to this post - Article Author for a Blog

Pardon me, but I don't really understand how to go about getting the author's name and display picture? Shouldn't this be native since usually we accredit a blog post to its author and most of the time include their display picture?

Otherwise, I don't particularly understand the comment on "creating a unique custom type tag" I have referred to the post (Create a custom tagging system - FAQs - Prismic People). How do I go about creating custom tags?

I'm really looking for a solution that could show me a blog as such where it shows the display name and image. Thank you so much for the help!

Hello @gabrielszewh,

Welcome to the Prismic Forum.

To get the author's detail on the blog post, you need to do the following things:

  1. Create a blog post and author documents in the Prismic.
  2. Give the Content relationship field in the blog post Custom-Type. So in the blog post documents, you can use this field to link to the author's document.
  3. Now, you need to use fetchLinks in your code. fetchLinks fetches a specific content field from a linked document. Find more detail here.

This is in javascript but you can find documentation in the different frameworks as well. What framework are you using?

Thanks,

Priyanka

2 Likes

Hi @Priyanka ,

Thanks for getting back, I managed to figure it out. Thanks for the walkthrough.

However, I'm wondering if I could get all the documents authors when i retrieve them altogether, with a command via

const blogPosts = await $prismic.api.query(
        $prismic.predicates.at("document.type", "post"),
        { orderings: "[my.post.date desc]" }
      );

Could I retrieve the author's name and image when I'm getting the posts as a group as such?

Hello gabrielszewh,

You need to use fetchLinks in your code. In your fetchLinks array, the value should be:

  • First, the API ID of the custom type referenced in your content relationship field.
  • Then, the API ID of the field that you want to retrieve.

So, if you have a custom type called “post” that includes a content-relationship field called which link to a custom type called “author,” your query will be:

await $prismic.api.query(
   $prismic.predicates.at('document.type','post'),
  { fetchLinks: ['author.name', 'author.image'] }
)

Let me know if you have any doubt.

Thanks,

Priyanka

3 Likes

Thanks for clarifying! I managed to solve it, thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.