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.


<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() ?>

<?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 ?>

<?php endforeach ?>


title: Authors

  preview: false
  status: false
  template: author

    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.


title: author

  status: false

pages: false

    label: Name
    type:  text

    label: Biography
    type: textarea

    label: E-mail
    type: text

    label: Website
    type: text

    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 ?>

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:

    label: Author
    type: select
    options: 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: