Complete and flexible blogging platform for ProcessWire

Render Authors

renderAuthors() enables you to output a list of your Blog Authors. The output also shows the number of Posts by each Author.

<?php
 /**
 * Renders a list of Blog authors.
 *
 * @access public
 * @param PageArray $authors
 * @return $out string
 *
 */
 public function renderAuthors(PageArray $authors)

This small function accepts one argument only, $authors. This has to be a PageArray of your Blog Authors. By PageArray we refer not to typical ProcessWire pages but Users. In ProcessWire, Users are also stored as 'pages'. The code below explains how to use this method.

<?php
//first we call MarkupBlog
$blog = $modules->get('MarkupBlog');

//we want to only return users with the role 'blog-author'
$authorRole = $roles->get('blog-author');

//find the authors
$authors = $users->find("roles=$authorRole, sort=title");

//render the list of authors
echo $blog->renderAuthors($authors); 

renderAuthors() HTML output

Below is the markup output by renderAuthors().

<ul class="authors posts-group">
<!-- list with author names and their posts' counts -->
 <li><a href="">John Smith</a> <span class="num-posts">2</span></li>
 <li><a href="">James Kasiki</a> <span class="num-posts">9</span></li>
 <li><a href="">Melissa May</a> <span class="num-posts">1</span></li>
 <li><a href="">Kazakuna Yokozama</a> <span class="num-posts">3</span></li>
 <li><a href="">Richard Jones</a> <span class="num-posts">1</span></li>
 <li><a href="">Paula Okagbuba</a> <span class="num-posts">2</span></li>
</ul>

renderAuthors() CSS

The CSS attributes output with renderAuthors() markup is shown below.

ul.authors, ul.posts-group {}
span.num-posts {}

Summary

In this short lesson we learnt how to use the method renderAuthors($authors). This method allows us to output a list of Blog Authors.