我要实现自定义网址,作者。WordPress的自定义网址,作者
目前笔者URL是这样的: http://site.com/author/author-name/
我要像做 http://site.com/my-custom-url-here
为每个用户。 我一直在使用author_rewrite_rules
过滤器,使用下面的代码试过,这个正确转换网址,但这给了我一个找不到网页的消息,当我浏览网址
add_filter('author_link', 'no_author_base', 1000, 3);
function no_author_base($link, $author_id) {
$link_base = trailingslashit(get_option('home'));
$link = preg_replace("|^{$link_base}author/|", '', $link);
return $link_base . $link;
}
add_filter('author_rewrite_rules', 'no_author_base_rewrite_rules');
function no_author_base_rewrite_rules($author_rewrite) {
global $wpdb;
$author_rewrite = array();
$authors = $wpdb->get_results("SELECT user_nicename AS nicename from $wpdb->users");
foreach($authors as $author) {
$author_rewrite["({$author->nicename})/page/?([0-9]+)/?$"] = 'index.php?author_name=$matches[1]&paged=$matches[2]';
$author_rewrite["({$author->nicename})/?$"] = 'index.php?author_name=$matches[1]';
}
return $author_rewrite;
}
任何帮助将不胜感激!
谢谢。 UPDATE
问题解决!基本上我不知道调用flush_rewrite_rules
函数。
后您实现的代码,你访问管理 - >永久链接页面刷新重写规则? – diggy 2013-05-04 22:08:45
@diggy我不知道这件事情,我知道了,就在这里:http://wordpress.stackexchange.com/questions/5413/need-help-with-add-rewrite-rule看到我的回答:) – Shaheer 2013-05-04 22:17:55