当前位置:首页 »“秋了秋”个人博客 » WP教程 » wordpress的current_user_can依照会员等级显示不同的內容

wordpress的current_user_can依照会员等级显示不同的內容

作者:秋了秋 发表时间:2014年10月18日

WordPress 会员等级

首先先来了解WordPress会员的等级划分:

  1. 管理(Administrator): level 10
  2. 编辑(Editor): Level 7
  3. 作者(Author): Level 4
  4. 撰写人员(Contributor): Level 2
  5. 订阅者(Subscriber): Level 0
  6. 一般访客(非会员): Level 在 0 以下

以下将使用官方提供的函数: current_user_can 来做会员等级区分。

仅允许管理员浏览

<?php global $user_ID; if( $user_ID ) : ?>
<?php if( current_user_can('level_10') ) : ?>
这里只显示管理员可看到的内容
<?php endif; ?>
<?php endif; ?>

依照会员等级显示不同的內容

<?php if (current_user_can('level_10')) : ?>
管理员可看到
<?php elseif (current_user_can('level_7')) : ?>
编辑可看到
<?php elseif (current_user_can('level_4')) : ?>
作者可看到
<?php elseif (current_user_can('level_2')) : ?>
撰写者可看到
<?php elseif (current_user_can('level_0')) : ?>
订阅者可看到
<?php else : ?>
一般非会员(未登入者)可看到
<?php endif; ?>
0
文章作者: “秋了秋”个人博客,本站鼓励原创。
转载请注明本文地址:http://netblog.cn/blog/146.html
目录: WP教程标签: wordpress,会员等级 24062次阅读

请求播放音乐,请点击播放

登 录
点击获取验证码
还没账号?点击这里