从…起this question:
您可以使用几个过滤器来完成此操作:
<?php
function wpse_112719_pre_post_link( $permalink, $post, $leavename ) {
if ( strpos( $permalink, \'%author%\' ) !== false ) {
$authordata = get_userdata( $post->post_author );
$author_id = $authordata->ID;
$permalink = str_replace( \'%author%\', $author_id, $permalink );
}
return $permalink;
}
add_filter( \'pre_post_link\', \'wpse_112719_pre_post_link\', 10, 3 );
function wpse_112730_add_rewrite_rules() {
add_rewrite_rule(
"([0-9]+)/(.*)",
\'index.php?name=$matches[2]\',
\'top\'
);
}
add_action( \'init\', \'wpse_112730_add_rewrite_rules\' );
现在,转到设置→ Permalinks并将Permalinks设置为
/%author%/%postname%/
. 保存您的更改,您的链接应该会相应地工作。如果您有任何问题,请告诉我!