在《十二个主题》中twentytwelve_entry_meta()
函数显示“按作者”链接(即标题为“按xxxx查看所有帖子”)通过使用user_nicename
. 因此,当选择“困难”的管理员用户名时,该链接可能类似于:
<a href="http://example.com/author/site_admin_45471/">John Smith</a>
有没有办法改变这种状况
twentytwelve_entry_meta()
功能,并保留指向作者其他帖子的链接,但在链接正文中使用“user\\u nicename”以外的其他内容?E、 g.:
<a href="http://example.com/author/author_id/">John Smith</a>
update:
My(与默认值相比略有更改)twentytwelve_entry_meta()
功能:
function twentytwelve_entry_meta() {
// Translators: used between list items, there is a space after the comma.
$categories_list = get_the_category_list( __( \', \', \'twentytwelve\' ) );
// Translators: used between list items, there is a space after the comma.
$tag_list = get_the_tag_list( \'\', __( \', \', \'twentytwelve\' ) );
$date = sprintf( \'<time class="entry-date" datetime="%3$s">%4$s</time>\',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( \'c\' ) ),
esc_html( get_the_date() )
);
$author = sprintf( \'<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>\',
esc_url( get_author_posts_url( get_the_author_meta( \'ID\' ) ) ),
esc_attr( sprintf( __( \'View all posts by %s\', \'twentytwelve\' ), get_the_author() ) ),
get_the_author()
);
// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author\'s name.
if ( $tag_list ) {
$utility_text = __( \'Posted on %3$s<span class="by-author"> by %4$s</span>\', \'twentytwelve\' );
} elseif ( $categories_list ) {
$utility_text = __( \'Posted on %3$s<span class="by-author"> by %4$s</span>\', \'twentytwelve\' );
} else {
$utility_text = __( \'Posted on %3$s<span class="by-author"> by %4$s</span>\', \'twentytwelve\' );
}
printf(
$utility_text,
$categories_list,
$tag_list,
$date,
$author
);
}
来自明显重复问题的重写函数:
// add our custom rewrite rules for author archives
add_action(\'author_rewrite_rules\', \'my_author_rewrite_rules\');
function my_author_rewrite_rules() {
$author_rules[\'author/([0-9]+)/?$\'] = \'index.php?author=$matches[1]\';
$author_rules[\'author/([0-9]+)/page/?([0-9]{1,})/?$\'] = \'index.php?author=$matches[1]&paged=$matches[2]\';
$author_rules[\'author/([0-9]+)/(feed|rdf|rss|rss2|atom)/?$\'] = \'index.php?author=$matches[1]&feed=$matches[2]\';
$author_rules[\'author/([0-9]+)/feed/(feed|rdf|rss|rss2|atom)/?$\'] = \'index.php?author=$matches[1]&feed=$matches[2]\';
return $author_rules;
}
在此之后,我重新保存了permalinks。此后,作者URL没有更改;此外,单击URL现在返回404。不确定是否需要进一步修改
twentytwelve_entry_meta()
添加后的函数
my_author_rewrite_rules()
作用