作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的 WordPress 主题中创建了一个自定义的author.php页面,它成功地从数据库中提取了所有成员的详细信息。
我想在提供详细信息之前添加一条 if 语句,该语句仅显示信息 if a _mgm_user_status = expired
。 _mgm_user_status
在数据库中为 wp_usermeta
。这些详细信息都在数据库中,我只是不知道如何预先添加 if 语句。
如果用户状态不是“过期”,所有信息都应照常获取。如果它“过期”,则应显示警告,如“<p>Sorry, user not found</p>
” '.
感谢您对这些人的帮助。
像这样?
<?php
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are currently not logged in.';
} else {
echo 'You are logged in as user '.$user_id;
}
?><?php
$userID = intval($author);
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif;
?><?php $is_expired = get_user_meta($user_id, '_mgm_user_status', true);
if(!empty($is_expired) && $is_expired == 'expired') {
echo 'Sorry, user not found';
}
?>
<ul class="profile-list">
<li>
<?php echo get_avatar($curauth->ID, 95, get_bloginfo('template_url').''); ?></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>
<li><strong>Job Title:</strong>
<?php echo $curauth->_mgm_cf_job_title; ?></li>
<li><strong>Email:</strong> <?php echo $curauth->_mgm_cf_email; ?></li>
<li><strong>Organisation:</strong>
<?php echo $curauth->_mgm_cf_organisation; ?></li>
<li><strong>Type of Organisation:</strong>
<?php echo $curauth->_mgm_cf_types_of_organisation; ?></li>
<li><strong>Service Provided:</strong>
<?php echo $curauth->_mgm_cf_service; ?></li>
<li><strong>Address:</strong>
<?php echo $curauth->_mgm_cf_address; ?></li>
<li><strong>Town/City:</strong>
<?php echo $curauth->_mgm_cf_city; ?></li>
<li><strong>County:</strong>
<?php echo $curauth->_mgm_cf_state; ?></li>
<li><strong>Postcode:</strong>
<?php echo $curauth->_mgm_cf_zip; ?></li>
<li><strong>Region:</strong>
<?php echo $curauth->_mgm_cf_region; ?></li>
<li><strong>Country:</strong>
<?php echo $curauth->_mgm_cf_country; ?></li>
<li><strong>Telephone:</strong>
<?php echo $curauth->_mgm_cf_phone; ?></li>
<li><strong>Mobile:</strong>
<?php echo $curauth->_mgm_cf_mobile; ?></li>
<li><strong>Fax:</strong> <?php echo $curauth->_mgm_cf_fax; ?></li>
<li><strong>Website:</strong>
<?php echo $curauth->_mgm_cf_website_url; ?></li>
<li><strong>Other Info:</strong>
<?php echo $curauth->_mgm_cf_other_info; ?></li>
</ul>
最佳答案
我编辑了这段代码。这对你来说很有效。
<?php
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are currently not logged in.';
} else {
$curauth = get_userdata(intval($user_id));
$is_expired = get_user_meta($curauth->ID, '_mgm_user_status', true);
if(!empty($is_expired) && $is_expired == 'expired') {
echo 'Sorry, user not found';
}else {
?>
<ul class="profile-list">
<li>
<?php echo get_avatar($curauth->ID, 95, get_bloginfo('template_url').''); ?></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>
<li><strong>Job Title:</strong>
<?php echo $curauth->_mgm_cf_job_title; ?></li>
<li><strong>Email:</strong> <?php echo $curauth->_mgm_cf_email; ?></li>
<li><strong>Organisation:</strong>
<?php echo $curauth->_mgm_cf_organisation; ?></li>
<li><strong>Type of Organisation:</strong>
<?php echo $curauth->_mgm_cf_types_of_organisation; ?></li>
<li><strong>Service Provided:</strong>
<?php echo $curauth->_mgm_cf_service; ?></li>
<li><strong>Address:</strong>
<?php echo $curauth->_mgm_cf_address; ?></li>
<li><strong>Town/City:</strong>
<?php echo $curauth->_mgm_cf_city; ?></li>
<li><strong>County:</strong>
<?php echo $curauth->_mgm_cf_state; ?></li>
<li><strong>Postcode:</strong>
<?php echo $curauth->_mgm_cf_zip; ?></li>
<li><strong>Region:</strong>
<?php echo $curauth->_mgm_cf_region; ?></li>
<li><strong>Country:</strong>
<?php echo $curauth->_mgm_cf_country; ?></li>
<li><strong>Telephone:</strong>
<?php echo $curauth->_mgm_cf_phone; ?></li>
<li><strong>Mobile:</strong>
<?php echo $curauth->_mgm_cf_mobile; ?></li>
<li><strong>Fax:</strong> <?php echo $curauth->_mgm_cf_fax; ?></li>
<li><strong>Website:</strong>
<?php echo $curauth->_mgm_cf_website_url; ?></li>
<li><strong>Other Info:</strong>
<?php echo $curauth->_mgm_cf_other_info; ?></li>
</ul>
<?php
}
}
?>
关于php - WordPress 'If' 声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25786626/
我是一名优秀的程序员,十分优秀!