Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
so the answer is both? :) thanks for the reply Tom. index.php?author_page=author_page does trigger the author listing template.. but /author still 404s. i did re-save my permainks. –  helgatheviking Aug 26 '12 at 22:27
    
try variations in the rewrite rules additon such as /author/ author/ /author etc –  Tom J Nowell Aug 27 '12 at 0:08
    
I've also added a return statement, all filters should return what they're passed ( albeit modified ) –  Tom J Nowell Aug 27 '12 at 0:10
    
yes must return, or pass $wp_rewrite by reference, or add_action('generate_rewrite_rules','ex_rewrite'); where it is passed by reference automatically. that was step 1. step 2 was changing the rule match to : 'author/?$' . i var_dumped the $wp_rewrite->rules and saw the /$ character at the end of custom post type archives. and the last part was reversing the union of arrays to $feed_rules + $wp_rewrite->rules . this puts the new rule at the top so it is processed first. also can do add_rewrite_rule() on the init hook. all work. can you edit your answer so I can mark it as correct? thanks! –  helgatheviking Aug 27 '12 at 2:20
    
cursory testing of pagination makes me think we need a second rule to read the 'paged' parameter: add_rewrite_rule('author/?page/([0-9]{1,})/?$','index.php?author_page=author_pag‌​e&paged=$matches[1]','top'); though i am lost on how to implement the rest of pagination (namely creating a 'next authors' style link b/c w/ posts you'd just use the paged var as the offset, but i don't think authors work that way) but i will leave that for another question. thanks again. –  helgatheviking Aug 27 '12 at 2:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.