由于文件位于主题目录中,Wordpress可能不希望用户“直接”访问它。为什么不在wordpress中创建一个页面,为您的PHP页面指定一个模板名称,然后将其指定给在wordpress中创建的新页面。例如,您将有一个名为“仅成员”的新页面,其模板是“位于主题中的php页面”。然后,在代码中,您不必调用博客标题,只需将整个页面包装在“Is user logged in”if else语句中即可。
示例:
<?php
Template Name: php-page-located-in-theme
get_header();
if ( is_user_logged_in() ) {
echo \'Welcome, registered user!\';
/*PHP Generated Content Goes Here*/
} else {
echo \'You cannot access this page.\';
}
get_sidebar();
get_footer();
?>