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

I know how to query the users and create a list of authors and can accomplish this in a page template, much like is described here:
Authors Page : A page of authors

my question is then….

Read More

is there a way so that i can have www.site.com/author resolve to the page where I am displaying a list of all authors?

I just attempted to create a static page w/ an ‘author’ slug and it unsurprisingly 404s, I presume b/c WP is expecting something to follow ‘author’ and nothing is.

Do I create an endpoint (rewrite stuff is still complex for me) or can I intercept the template_redirection and send it to my custom page? Any push in the right direction would be most appreciated.

Related posts

Leave a Reply

1 comment

  1. 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.