1

Please help me solve this problems:

Problem 1

AFAIK,

http://exmaple.com/author

maps to nothing (a 404 error page) and

http://exmaple.com/author/{username}

maps to posts authored by {username}. I need to change this behavior to something else:

  1. I need that http://example.com/author maps to list of authors
  2. I need that http://example.com/author/{username} maps to some profile information (I hope this could be done by adding a template file like author.php in theme's root)

Problem 2

At the same time, I need to prepend all of my posts with /blog like:

http://example.com/blog/this-is-my-first-post

It could be done by changing Permalinks Structure to /blog/%post_name%, but it changes the author url too:

http://example.com/blog/author
http://example.com/blog/author/{username}

which is not desired in my case.

Please help me:

  1. prepend ONLY posts with /blog
  2. have a list of authors in http://example.com/author
  3. have a user profile for all authors in http://example.com/author/{username}

Thanks in advance

2

For the list of authors, the simplest solution is to create a page with the slug author, then create a page-author.php template where you'll add your own code to list authors.

All views in WordPress are a post or list of posts- there's no concept of an author list, or a list of terms in a taxonomy, those things need to be created manually.

For the author links, the fix is fairly simple, you can manually set the structure they follow to omit the front value that gets inserted by default:

function wpd_fix_author_structure(){
    global $wp_rewrite;
    $wp_rewrite->author_structure = 'author/%author%';
}
add_action( 'init', 'wpd_fix_author_structure' );

Don't forget to flush rewrite rules after they change.

  • tnx, but if I go with 'page-author.php' how can I have routes for 'example.com/author/{username} – Pmpr Jan 8 '18 at 20:11
  • 1
    that's what the above code does. – Milo Jan 8 '18 at 20:17
  • Thank u very much, i'll give it a try and come back ASAP – Pmpr Jan 8 '18 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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