我需要一些关于PHP的帮助。
http://www.domain.com/author/username/成就/
根据登录者的用户名,我想创建一个URL,将用户重定向到上述页面。为此,username 需要用其登录的用户名替换。
有没有简单的方法可以做到这一点?
我需要一些关于PHP的帮助。
http://www.domain.com/author/username/成就/
根据登录者的用户名,我想创建一个URL,将用户重定向到上述页面。为此,username 需要用其登录的用户名替换。
有没有简单的方法可以做到这一点?
WordPress具有多个获取用户信息的功能,例如以下功能:
您可以使用wp_get_current_user()
这应该可以做到:
$current_user = wp_get_current_user();
if ( is_user_logged_in() ) {
wp_redirect( \'http://www.domain.com/author/\'.$current_user->user_login.\'/achievements/\');
exit;
} else {
echo \'You have no business being here\';
}
另请参见wp_get_current_user()
文档如果您在以下环境中运行:Warning: Cannot modify header information - headers already sent by
将此添加到functions.php
:
add_action(\'init\', \'do_output_buffer\');
function do_output_buffer() {
ob_start();
}
我需要使用URL参数?m=1 用不同的模板加载wordpress的每个页面,但问题是我无法提取可以使用规范URL访问的文本和帖子我尝试了不同的方法,对我来说最好的方法是使用template_redirect 行动挂钩或template_include 过滤器问题是,我无法使用任何这种方法将数据加载到模板文件中模板加载,但页面是空的,使用某些方法,它会返回404错误,以便更好地解释我的问题我将此代码添加到functions.phpadd_filter( \'template_include\', \'cus