用于注销和登录用户的不同 WordPress 首页 [英] Different WordPress front page for logged out and logged in users
问题描述
WordPress 阅读设置可以在设置 > 阅读下找到.
The WordPress reading settings can be found under Settings > Reading.
我将 WordPress 的首页显示"选项设置为静态首页".
I have the WordPress 'Front page displays' option set to 'Static front page'.
我的首页"设置为关于".
My 'Front page' is set to 'About'.
我正在尝试为注销和登录用户使用不同的首页.目前,每个人在访问 example.com 时都会查看关于"页面.
I am trying to have a different front page for logged out and logged in users. Currently everyone views the 'About' page when they visit example.com.
- 如果我在登出后访问 example.com,我想查看我的关于页面"
- 如果我在登录时访问 example.com,我想查看我的联系页面"
有人知道我是如何做到这一点的吗?
Does anybody know how I can achieve this?
推荐答案
可以以编程方式设置 front page
但不确定这是否可以解决您的问题,因此,将此代码粘贴到您的 functions.php
文件并试一试
It's possible to set the front page
programmatically but not sure if this is a solution to your question, so, paste this code in your functions.php
file and give it a try
if( is_user_logged_in() ) {
$page = get_page_by_title( 'Contact Me');
update_option( 'page_on_front', $page->ID );
update_option( 'show_on_front', 'page' );
}
else {
$page = get_page_by_title( 'About Me' );
update_option( 'page_on_front', $page->ID );
update_option( 'show_on_front', 'page' );
}
P/S:未测试,请尝试一下,请回复您所得到的.
P/S: Not tested, just try it and please response what you get.
这篇关于用于注销和登录用户的不同 WordPress 首页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!