Help with author pages

I explained that above. I got it working on a test I did, so hopefully you can duplicate it.

Thanks, I got the bio example working (added on _index.md) and processed on /taxonomy/author.html

So I can define things on the _index.md frontmatter and it will work great for the author profile pages.

I am less sure how I can grab bio and photo info to surface alongside the single.html and list.html, and this code doesn’t seem to work for me -

{{ range .Params.authors }}
{{$.Params.bio}} // bio is a frontmatter variable in the author taxonomy _index.md
{{ end }}

I just want to define “author” JOE at the content/post/text.md frontmatter and have all values (photo, name, bio) associated with JOE be available for me to add to layouts/post/list.html and layouts/post/single.html

Thats odd. I will have to check this tomorrow. Its possible I made an error here. :frowning: It worked on my initial test, because I only checked the name, and that must of been defined in the post front matter too in my example. So probably not right at all.

I am getting closer, but its late, so can’t do much more today:

{{ range where .Site.Pages "Type" "categories" }}
{{ .Params.testparams }}
{{ end }}

This will access the front matter of the taxonomy, and provide a full list of the correct parameter but for all authors. Now just need to add some further logic (i.e. where .Params.author = article .author, and will get the result needed. (I think).

wow, thanks man! Super appreciate the support. I’m less sure what I’m doing hahah.

{{ range where (where .Site.Pages "Type" "categories") ".Params.author" "=" "Jonathan Griffin" }}
{{ .Params.testparams }}
 {{ end }}

This works, but need to replace the name with the current content author. Getting closer.

Can you test this please:

{{ $postauthor := .Params.author }}
{{ range where .Site.Pages "Type" "categories"}}
{{ if eq .Params.author $postauthor }}
{{ .Params.testparams }}
{{end}}
{{ end }}

I think this works, but needs double checking.

I did change the author name in the _index.md and the testparam dissappeared. Probably needs testing with two authors to be sure.

Edit: It doesn’t work.

Edit2: I need to get a closer implementation to test further. I am just using test variables etc, and default categories.

After all that, I do believe I have cracked it.

{{ $postauthor := .Params.authors }}
{{ range where (where .Site.Pages "Type" "authors") ".Params.name" "=" $postauthor }}
{{ .Params.testparams }}
{{ end }}

I shall probably implement this on my own site tomorrow. This was a good learning experience.

Edit: I think I still have a few tweaks to do. Almost there.

hey @Jonathan_Griffin, it feels so close! I tried your last piece of code but for some reason, it doesn’t render anything. If I remove the first “where” from range, then it does work and I can access all the fields in the _index.md frontmatters, but it shows it for every author and not just the one the page belongs to. Can you send me a copy of your frontmatter in _index.md and the post’s to compare? I have “name” in there, but either it’s not finding anything, or the condition you have to check name against author is returning false :confused:

I need to tweak my site a little to integrate the code I put properly. I will then test again, and make any changes as necessary, although I think it should still work (but it does need testing again properly to be sure).

It may be a few hours until I can look at this again, as some other things to attend to first. I can then try and clarify things for you.

1 Like

Yeh, so it still needs some refining.

It works if in the post front matter you have:

authors: Jonathan Griffin

But what we want is (yaml):

authors:
    - Jonathan Griffin

Therefore, we need to add a step to iterate through, and add multiple author functionality. This will have to wait until the evening \ weekend for me to look at.

Okay, thanks. Yeah, the way I was doing it was like this -

authors: [ “alan”, “joe”]

But it does work when I just make it authors: alan !

So at least single author is working as expected. You’re da man! Looking forward for the fix for multiple authors :smiley:

1 Like

I haven’t had time to look at this further, and probably won’t have chance for a while. I have to prioritize other work at the moment.

Okay, thanks Jonathan. Single author works as of now, which does the trick. Multi-author support would be amazing down the road, if only to cover this use-case. If you do get around to it, please let me know. Again, amazing support and very much appreciated!

This is a crazy long thread, so I’m a bit lost, but am I missing something w/r/t the idea of “multiple authors?” Why not a simple authors taxonomy?

This thread was more of a learning exercise for me ( a newbie), helping out someone else. Hence the long thread, as I started off not really knowing how to implement it.

The implementation was using authors taxonomy, but the difficulty related to displaying things like bio \ photo etc on post article page.

Displaying all that info on the taxonomy page is not really an issue, as that is fairly simple.

We managed to retrieve the information from the taxonomy _index.md file for single authors to display on the post article page, but unfortunately it was like 3 am in the morning when I was looking at this, and haven’t had time to look into it working with multiple authors.

@rdwatters That is what we went with, but the code that grabs and compares the frontmatter in each individual _index.md (pertaining to a single author) currently does not work when using multiple authors in a post’s frontmatter.

To summarize, in multiple _index.md, for each author, I have frontmatter like this:

name: Joe
bio: this is a bio
photo: /path/to/img/

Then when creating a post, there is an authors taxonomy in the front matter, which lets us specify N number of authors. However, the code to match Joe and also extract the bio and photo from his _index.md for use across list and single pages currently only loops through a single author properly.

so this works:

authors: Joe

but this does not:

authors: [ "alan", "joe"]

and the code that Jonathan wrote that needs to support multiple authors is this -

{{ $postauthor := .Params.authors }}
{{ range where (where .Site.Pages "Type" "authors") ".Params.name" "=" $postauthor }}
{{ .Params.testparams }}
{{ end }}

Any help is much appreciated.

Gotcha. Thanks for the update. Frankly, it was my bad for being lazy and not reading the preceding comments :smile:

So here is what I would recommend:

  1. I assume you have author = "authors" in your config.toml under [taxonomies].
  2. I assume, for example, that if you have an author named Ryan Watters, you have a content file for said author at content/authors/ryan-watters/_index.md.
  3. I assume that when you add an author to a content file, you do so using authors = ["Ryan Watters", "John Doe"], etc…

So here is what you need for something like layouts/_default/single.html:

<!--Somewhere in layouts/_default/single.html-->
{{ with .Params.authors }}
      {{ range $ind,$val := . }}
           {{$author := $val | urlize }}
           {{- with $.Site.GetPage "taxonomyTerm" "authors" $author}}
           <p>Name = {{ .Params.name }} </p>
           <p>Bio = {{ .Params.bio }}</p>
           <p>Photo = {{.Params.photo}}</p>
           <p>Here is the content from this author's _index.md file:</p>
          {{.Content}}
      {{ end -}}
  {{ end }}
{{ end }}

Obviously you can use whatever elements you want…

2 Likes

Thanks @rdwatters! Your assumptions are all correct. I tried your code and it errored out when I had some content pages with authors: alan (as that was what worked before with Jonathan’s code).

I switched to the multi-format you listed above and there are no Hugo errors. However, I am not seeing your code displayed on the page. I added text around it to make sure it wasn’t weird caching, and nothing in your code renders. Is there any way to console.log hugo steps to the CLI? Or how would I go about debugging this, if your code is working on your end?