默认情况下,我使用author.php
模板,工作正常,但我需要为author.php
比如facebook和其他社交网站。
我想这样做:
site.com/author/trello/settings
site.com/author/trello/personalinformation
默认情况下,我使用author.php
模板,工作正常,但我需要为author.php
比如facebook和其他社交网站。
我想这样做:
site.com/author/trello/settings
site.com/author/trello/personalinformation
您可以使用如下新的重写规则添加此页面:
add_action("init", function () {
add_rewrite_tag("%specialAuthor%", "([^&]+)");
foreach (["personalinformation", "settings"] as $specialAuthor) {
add_rewrite_rule(
"author/([^/]+)/($specialAuthor)/?$"
, "index.php?author_name=\\$matches[1]&specialAuthor=\\$matches[2]"
, "top"
);
}
});
add_filter("author_template_hierarchy", function ($templates) {
$specialAuthor = get_query_var("specialAuthor", NULL);
if (isset($specialAuthor)) {
$author = get_queried_object();
$templates = [
"$specialAuthor-{$author->user_nicename}.php",
"$specialAuthor-{$author->ID}.php",
"$specialAuthor.php",
];
}
return $templates;
});
第一次刷新重写规则:https://codex.wordpress.org/Function_Reference/flush_rewrite_rules然后,复制author.php
到personalinformation.php
在URL的主题中site.com/author/.../personalinformation
WordPress无法独自做到这一点。作者页面仅是具有已发布帖子的用户的存档。您需要的更多是WordPress的社交网络使用,您应该尝试BuddyPress插件:BuddyPress. 它将为所有用户创建成员页面,并为每个用户创建不同的页面:配置文件编辑、配置文件视图、设置。。。它可能比您需要的更多,但这最接近于激活配置文件。
还有其他用于会员制网站的插件,您可以在其中为用户提供广泛的配置文件,您可以在WordPress存储库中找到它们:Members plugins on WP.org.
我想在菜单中添加一个登录/注销按钮,所以我在我的子主题函数中添加了以下php代码。php:add_filter( \'wp_nav_menu_items\', \'add_loginout_link\', 10, 2 ); function add_loginout_link( $items, $args ) { if (is_user_logged_in() && $args->theme_location == \'primary\') {