Tidyup PHP if else功能

时间:2014-09-18 19:47:08

标签: php wordpress if-statement

我真的很挣扎(作为一个PHP新手)来整理这些代码并使其工作(wordpress中的语句中的语句)。希望你能够从下面的代码中了解我想要做的事情:

感谢您的帮助......

<?php
/**
* The template for displaying Author archive pages
*
* @link http://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Thirteen
* @since Twenty Thirteen 1.0
*/

get_header(); 

//phpinfo();
?>

<div class="slider non-home">
<div class="homebanner">
<div class="home royalSlider">
<div class="rsImg"></div>
</div>
</div>
</div>
<div class="main" style="margin-top:20px;">
<div class="hundred">
<div class="page-header">
<?php $userID = intval($author);
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif; ?>
<ul class="profile-list">
<?php
if ($curauth->_mgm_user_status; > 'expired') {
echo "
<li><strong>Status:</strong> <?php echo $curauth->_mgm_user_status; ?></li>
<li><strong>Member No.:</strong> <?php echo $curauth->_mgm_cf_membership_id; ?></li>
<li><strong>Title:</strong> <?php echo $curauth->_mgm_cf_title; ?></li>
<li><strong>First Name:</strong> <?php echo $curauth->first_name; ?></li>
<li><strong>Surname:</strong> <?php echo $curauth->last_name; ?></li>
</ul>

";
} else {
echo "Sorry, this user has expired";
}
?>
</div>
<div class="col13">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("page_sidebar") ) : ?>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>

这一切都回声并在前端产生数据,但我只是不能只显示$ curauth-&gt; _mgm_user_status位是否等于'过期'。

2 个答案:

答案 0 :(得分:2)

if ($curauth->_mgm_user_status != 'expired')
   {
     echo "<li><strong>Status:</strong>".$curauth->_mgm_user_status."</li>
    <li><strong>Member No.:</strong> ". $curauth->_mgm_cf_membership_id."</li>
    <li><strong>Title:</strong> ". $curauth->_mgm_cf_title."</li>
    <li><strong>First Name:</strong> ". $curauth->first_name."</li>
    <li><strong>Surname:</strong> ". $curauth->last_name."</li>
   </ul>";
    } 
else 
    {
     echo "Sorry, this user has expired";
 } 

答案 1 :(得分:0)

这有效:

if ($curauth->_mgm_user_status == 'Active')

谢谢Kamel!