Monday, December 14, 2009

Listing Authors in a WordpressMU page

I'm trying to give my staff more of a presence on GamesPlusBlog. They need to feel ownership of their piece of the blog and their content within.

One way of doing this is recognizing when authors join the site. For awhile now, our About Us page only displayed the three founders of the blog - Tim, Mike, and me. Ever since we began bringing on new writers, Mike has suggested we list them on this page. Pragmatic programmer that I am, however, I didn't want to have a list to curate every time an Author joined the site.

The obvious solution is have PHP and Wordpress generate a list of blog authors and display them onto the About Us page. Simple enough: a quick Google and I find the wp_list_authors function. However, Wordpress prohibits PHP code from executing on its pages and posts.

Another Google and the EXEC-PHP plugin looks like the key. Unfortunately I'm also working with WordpressMU.

Because WPMU is meant for use as a public, open blogging platform, like or Blogger, it assumes any of your posts and pages are created by untrustworthy user accounts. Thus, it presents its own set of 'security' filters for posts and pages. We at GPB are using WPMU as a centralized, private blogging platform to simplify management for multiple blogs - not how WPMU was meant to be used. WPMU strips any PHP tags from posts.

Writing a small Wordpress Plugin to recognize a shortcode was my solution. Much like Wordpress galleries and captions, shortcode can be used in articles and pages without WPMU freaking out on you.

Here's my code - well sort of. Blogger likes to strip html tags from articles. I had ul tags surrounding the author list in the output string, but those aren't entirely necessary.

add_shortcode('gpb_listauthors', 'gpb_listauthors_shortcode');
function gpb_listauthors_shortcode($atts, $content=null)
$args = array(

$output = wp_list_authors($args);

return $output;

Initially I echoed the code directly in the gpb_listauthors_shortcode function. This would output the list at the top of my Page. The solution was to build a string and return it. Hence the echo = false argument.

Ah, a nice list of my writers:

1 comment:

煩惱 said...
This comment has been removed by a blog administrator.