resolve /author/ to a page or archive (of all authors) template

If you use code similar to setup the rewrite rules:

function ex_rewrite( $wp_rewrite ) {

    $feed_rules = array(
        'author/?$'    =>  'index.php?author_page=author_page'
    );

    $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
    return $wp_rewrite;
}
// refresh/flush permalinks in the dashboard if this is changed in any way
add_filter( 'generate_rewrite_rules', 'ex_rewrite' );

followed by code to add the author_page as a valid query var:

add_filter('query_vars', 'add_my_var');
function add_my_var($public_query_vars) {
    $public_query_vars[] = 'author_page';
    return $public_query_vars;
}

You can then check for this in your functions.php, and call get_template_part to call your ‘authors’ template and list the authors out, e.g.:

add_action('template_redirect', 'custom_page_template_redirect');
fnction custom_page_template_redirect() {
    global $wp_query;
    $custom_page = $wp_query->query_vars['author_page'];
    if ($custom_page == 'author_page') {
        get_template_part('authorlisting');
        exit;
    }
}

Now all you need is an ‘authorlisting.php’ in your theme, and to flush your permalinks so the new rule takes effect. I wouldn’t add anything to the end of that rewrite rule however as it may interfere with the existing author rules, so be wary. Also you may have issues with pagination, but all I can say is to test it out.

Leave a Comment