Wordpress Hacks: Author.php, 404 Errors and Internet Explorer’s Friendly HTTP Error Messages

by Teresa Valdez Klein on April 9, 2007

When we rebuilt this site in Wordpress, one of our hot to-do items was to make it easy for the less HTML savvy members of our team to add bios and photos of our speakers. We accomplished this in three steps:

  1. Create a plugin that gives conference speakers an authorship role and has a custom template tag that will display only authors in that group.
  2. Create a standard author.php file that displays author bio and photo information.
  3. Override the Wordpress function that requires an author to have posts attributed to to them in order to pass the query to the author.php page.

Unfortunately, when you pass the author function in Wordpress and the author in question has no posts, Wordpress returns a 404 error. We originally solved the problem by adding the following PHP to our custom 404 page.


if( function_exists( 'bbs_is_author' ) && bbs_is_author()) {
include (TEMPLATEPATH.'/author.php');
} else {

This allowed the 404 page to pass the query along to the author.php page and display author information for authors (a.k.a. speakers) that have not written any posts in this system.

Unfortunately for us, Internet Explorer threw in a major hurdle. Unlike most browsers, Internet Explorer has friendly HTTP error messages that override our custom 404 page. Since IE users weren’t seeing our custom page, Wordpress didn’t know to pass the query to author.php page. Instead of the speaker information they requested, IE users were seeing a custom HTTP error message.

To rectify this, we modified the /wp-includes/classes.php file to pass the query to the author.php template rather than returning an HTTP error, regardless of whether the author had written any posts or not. If you are interested in learning more about the modification, you can e-mail me.

By the way, we’ll be covering more stuff like this at our next conference.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netscape
  • StumbleUpon
  • TailRank
  • NewsVine
  • Reddit

{ 1 comment… read it below or add one }

1

matt 09.10.08 at 10:36 pm

Hacking classes.php is one approach, but has pitfalls (e.g. the file gets overwritten the next time you upgrade Wordpress). After a couple late nights of research I found a better solution, and bundled it into a simple plug-in that causes Wordpress to retrieve posts _and_ pages when the user requests an author page. Details can be found on the Wordpress support site:
http://wordpress.org/support/topic/146716

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <p> <strike> <strong>