所以我在index.php上有以下代码:
<?php
define('WP_USE_THEMES', false); // Don't use WP themes
require('../wp-load.php'); // Allows the use of WP functions
?>
<?php // Check if the user is logged in. If not, show the login form
global $user_ID, $user_identity; get_currentuserinfo(); if (!$user_ID) { ?>
<script type="text/javascript">window.location.href='login.php';</script>
<?php } else { // If the user is logged in
include('header.php'); ?>
<div id="content">
<!-- Full Width Start -->
<div class="full-width">
<span class="full-width-red-left"></span>
<div class="full-width-red-wrapper">Department Chooser</div>
<span class="full-width-red-right"></span>
<div class="full-width-content">
<div id="panel-icons">
<?php // Display the menu for each department the user is a member of.
if(is_eventsStaff()){ eventsPanelIcon(); }
if(is_helpDeskStaff()){ helpPanelIcon(); }
if(is_hxlStaff()){ livePanelIcon(); }
if(is_newsStaff()){ newsPanelIcon(); }
if(is_raresStaff()){ raresPanelIcon(); }
if(is_panelAdmin()){ adminPanelIcon();} ?>
</div>
<div id="uploader-icon-wrapper">
<div class="panel-horizontal-split"></div>
<a href="#" id="upload-panel-icon"></a>
</div>
</div>
<div class="full-width-footer"></div>
</div>
<!-- Full Width End -->
</div>
</div>
<?php } else { echo "Test"; } }?>
然后header.php:
<link rel='stylesheet' href='CSS/build.css' type='text/css'/>
<title>Habbox Staff Panel</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<?php include_once('functions.php'); // Include staff panel functions ?>
<!-- Preload Image Hovers Start -->
<img src="images/topbar_home_hover.png" class="preload" />
<img src="images/topbar_admin_hover.png" class="preload" />
<img src="images/topbar_events_hover.png" class="preload" />
<!-- Preload Image Hovers End -->
<?php if(has_Roles()) { ?>
<!-- TopBar Start -->
<div id="topbar-wrapper">
<div id="topbar-inner-wrapper">
<span class="topbar-radio-text">Welcome <span class="bold red"><?php echo $user_login; ?></span></span>
<div class="topbar-divider"></div>
<a href="<?php echo $siteURL;?>/index.php" class="topbar-home"></a>
<?php
if (isset($_COOKIE['timezone'])) { date_default_timezone_set($_COOKIE['timezone']); } else { date_default_timezone_set('Europe/London'); }
if(is_eventsStaff()){
echo '<a href="'.$siteURL.'/Events/index.php" class="topbar-events"></a>';
}
// Check if the user is an admin
if(is_panelAdmin()){
echo '<a href="'.$siteURL.'/Admin/users.php" class="topbar-admin"></a>';
}
?>
<div id="topbar-logout">
<form>
<div class="darkbutton"><span class="darkbutton-left"></span><a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Log Out</a><span class="darkbutton-right"></span>
</div>
<input type="hidden" name="redirect_to" value="/Staff">
</form>
</div>
</div>
</div>
<!-- TopBar End -->
<div id="page-wrapper">
但是它给我带来了以下错误:
解析错误:语法错误,第43行中的index.php中的意外t_else
,但我不明白为什么。如果我将header.php的内容复制到index.php,但当我使用include。
通过include
读取代码并不等于复制和粘贴代码。所有涉及的文件都需要自己为有效的PHP代码:您不能在随附的文件中打开if()
并将其关闭在主文件中。PHP将分别解析每个文件并找到以下内容:
if(...){
}else{
}else{
}
...显然是非法的。
如果:
if (!$user_ID) {
<?php } else { // If the user is logged in
<?php } else { echo "Test"; } }?>
在header.php
中,您不会关闭此问题,如果:
<?php if(has_Roles()) { ?>
您可以在代码的这一部分中进行:
if(is_panelAdmin()){
echo '<a href="'.$siteURL.'/Admin/users.php" class="topbar-admin"></a>';
}
} // Closing has_roles() IF
?>
似乎我包含了错误,每个文件必须在其自我中是正确的语法。我只是将if and else语句放在header.php包含文件周围的索引文件中。一切似乎都起作用:)