WordPress按用户等級显示不同的內容

WordPress53.3K阅读模式

WordPress的用户机制在整体运作上似乎不是太重要的角色,如果前台针对不同等级的用户显示不同的页面或是内容,可用下面判断会员等级的语法,加以控制。。

WordPress按用户等級显示不同的內容

WordPress 用户等級

  • 管理员:Administrator: level 10
  • 编辑:Editor: Level 7
  • 作者:Author: Level 4
  • 投稿者:Contributor: Level 2
  • 订阅者:Subscriber: Level 0
  • 访客: Level 在 0 以下

仅管理員可见

  1. <?php global $user_IDif$user_ID ) : ?>
  2. <?php if( current_user_can('level_10') ) : ?>
  3. 管理员可见的内容
  4. <?php endif; ?>
  5. <?php endif; ?>

按照用户等級显示不同的內容

  1. <?php if (current_user_can('level_10')) : ?>
  2. 管理員可见内容
  3. <?php elseif (current_user_can('level_7')) : ?>
  4. 編輯可见内容
  5. <?php elseif (current_user_can('level_4')) : ?>
  6. 作者可见内容
  7. <?php elseif (current_user_can('level_2')) : ->
  8. 投稿者可见内容
  9. <?php elseif (current_user_can('level_0')) : ?>
  10. 订阅者可见内容
  11. <?php else : ?-->
  12. 一般访客可见内容
  13. <?php endif; ?-->

原文:http://sofree.tw/current_user_can/

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
评论  5  访客  5
    • 晓庄
      晓庄 1

      :razz: 这篇文章怎么的url是用的中文呢。鸟哥忘记改了吧

      • boke112导航
        boke112导航 5

        如果是综合站点,特别是有很多收费会员或文章的,这个功能挺实用的

        • masy
          masy 1

          代码有错,1.方括号里的横线要改正。2.用户级别对应不对,
          0 级对应 订阅者
          1 级对应 投稿者
          2 – 4 级对应 作者
          5 – 7 级对应 编辑
          8 – 10 级对应 管理员

        匿名

        发表评论

        匿名网友
        :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

        拖动滑块以完成验证