Cookbook Authoring System Not Working

I’m trying to create an authoring system using the cookbook approach however when I get to the authors.php template, it breaks giving me the error:

“Call to a member function children() on boolean”

So I altered it slightly to not use the find() function but it still isn’t pulling the articles and filtering them by author.

Authors.php

<main class="main m-scene" role="main">
<section class="wrap m-header scene_element scene_element--fadein" >
    <?php $authors = page('authors')->children() ?>
    <?php $articles = page('archive')->children() ?>
 <h1>Authors</h1>

<?php foreach($page->children() as $author): ?>
<article class="author">

  <h1><?php echo $author->name()->html() ?></h1>

  <ul class="articles">
    <?php foreach($articles->filterBy('author', $author->uid()) as $article): ?>
    <li><a href="<?php echo $article->url() ?>"><?php echo $article->title() ?></a></li>
    <?php endforeach ?>
  </ul>

</article>
<?php endforeach ?>
</section>
</main>

Authors.yml

title: Authors

options:
  preview: false
  status: false
pages:
  template: author

fields:
  info:
    label: About
    type: info
    text: >
      The Authors Page is used to add all of the authors you can then select when creating new article posts. After filling this out and then adding them to a article, they will be added to the contributors section and have their own page with all their articles listed.

Author.yml

title: author

options:
  status: false

pages: false

fields:
  name:
    label: Name
    type:  text

  biography:
    label: Biography
    type: textarea

  email:
    label: E-mail
    type: text

  website:
    label: Website
    type: text

  twitter:
    label: Twitter
    type: text

I suppose you mean your code is from the authors.php template, not author.php?

Yes. Thank you for catching that.

Will proofread more thoroughly in future posts.

So which line exactly causes the error? Please post a screenshot if possible.

Ah okay, I was troubleshooting some more and got the error to stop. Though the error was being caused by the variable declaration at the top. I had mixed up some of my naming conventions.

However I still can’t get any of the articles to show up and be filtered by the author using the Cookbook code:

<?php $articles = $pages->find('archive')->children() ?>>

  <ul class="articles">
    <?php foreach($articles->filterBy('author', $author->uid()) as $article): ?>
    <li><a href="<?php echo $article->url() ?>"><?php echo $article->title() ?></a></li>
    <?php endforeach ?>
  </ul>

How do you select your authors in your articles? What is in the content file for the author field in those pages?

I select them via a query:

  author:
    label: Author
    type: select
    options: query
    query:
      page: authors
      fetch: children
      value: '{{name}}'
      text: '{{name}}'

and then call it in the article code:

<h1><?php echo $page->author() ?></h1>

As for the content file question, I’m not entirely sure what you mean. This creates a drop down of the available authors and then upon selecting, it shows up in the article as “Author: {[name}}”.

Well, yes, but if you store the name of the author and then try to filter your articles by the uid instead of by name, you won’t get any result.

1 Like

Ah alright, I switched the uid variable to name and now it’s working!

Thanks. :slight_smile: